POSTDATA方法不执行功能 [英] postData method not executing function
问题描述
我有两个jqGrids。在第一栅极我选择一行和第二栅极与基于所述第一栅极的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:空}。
In Chrome I try to debug the function, getLobid() but it is never executed. The postData request sent: { lobId:null }.
如果我改变以上为code'{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');
}
}
请参阅答案了解更多详情。
更新时间::如果你需要使用 JSON.stringify
另外在 serializeGridData code>的那么你可以不使用更多的简单版本
serializeGridData code>:
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 code>的稍微复杂一点的版本,我的答案:
Instead of that you should use a little more complex version of serializeGridData
which I described in the answer:
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方法不执行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!