postData method not executing function(postData 方法不执行函数)
问题描述
我有两个 jqGrid.在第一个网格中,我选择一行,第二个网格根据第一个网格的 id 刷新数据.至少它应该是这样工作的.
I have two jqGrids. In the first grid I select a row and the second grid refreshes with data based on the id of the first grid. At least that is how it is supposed to work.
//This is code from the second grid
postData: '{ lobId: ' + BudgetCore.getLobId() + ' }',
//Snippet from BudgetCore...
getLobId: function () {
var row = jQuery(BudgetCore.GridTables.Lob).jqGrid('getGridParam', 'selrow');
return row;
}
在 Chrome 中,我尝试调试函数 getLobid() 但它从未执行过.发送的 postData 请求:{ lobId:null }.
In Chrome I try to debug the function, getLobid() but it is never executed. The postData request sent: { lobId:null }.
如果我将上面的代码更改为 '{ lobId: ' + 1 + ' }' 它可以工作,所以一定有什么错误导致这个函数无法执行.在 Chrome JS 控制台中执行 BudgetCore.getLobId() 工作正常.
If I change the code above to '{ lobId: ' + 1 + ' }' it works, so there must be something wrong that is causing this function not to execute. In the Chrome JS console executing BudgetCore.getLobId() works fine.
推荐答案
你应该使用
postData: {
lobId: function () {
return $(BudgetCore.GridTables.Lob).jqGrid('getGridParam', 'selrow');
}
}
有关详细信息,请参阅答案.
See the answer for more details.
已更新:如果你需要在 serializeGridData
内额外使用 JSON.stringify
那么你不能使用更简单的 <代码>serializeGridData:
UPDATED: If you need to use JSON.stringify
additionally inside of serializeGridData
then you can't use more the simplest version of serializeGridData
:
serializeGridData: function (postData) { return return JSON.stringify(postData); }
您应该使用我在 答案:
serializeGridData: function (postData) {
var propertyName, propertyValue, dataToSend = {};
for (propertyName in postData) {
if (postData.hasOwnProperty(propertyName)) {
propertyValue = postData[propertyName];
if ($.isFunction(propertyValue)) {
dataToSend[propertyName] = propertyValue(); // call the function
} else {
dataToSend[propertyName] = propertyValue;
}
}
}
return JSON.stringify(dataToSend);
}
这篇关于postData 方法不执行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:postData 方法不执行函数


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01