我在事件中有这个js代码:
var userData = tableWidget.grid('userData');
console.log(tableWidget.grid('userData'));
$.ajax({
"url": "../../server/query.aspx?tableEvent=reordercolumns&table=SubContractor",
"data": { dataColumnOrder: JSON.stringify(userData) },
"dataType": "json",
"type": "GET",
"error": function () {
console.log("Something wrong with the columns' reorder saving process");
}
});
让我们说userData有两个条件。事件发生之前和之后:
userData before event
:[a, b, c]
userData after event
:[a, c, b]
就我而言,当事件被触发时,console.log(tableWidget.grid('userData'));
包含应有的userData after event
。但是,当我通过ajax发送它时,在服务器中,该对象包含userData before event
。我假设ajax在对象完全更新之前发送对象。
我的问题是,ajax
完全更新后有没有办法执行var userData = tableWidget.grid('userData');
?
已更新:事实证明问题似乎发生在stringify
函数中。以下是包含和不包含stringify
的对象的屏幕截图:
没有字符串console.log(userData);
:
使用Stringify console.log(JSON.stringify(userData));
:
{
"view": "SubContractorGridView",
"title": "SubContractor Grid View",
"settings": {
"colOrder": ["Id", "ExtKey", "InsertionDate", "DeletionDate", "Name", "Address", "ZipCode", "EmailAddress", "PhoneNumber", "UserName", "Password", "LastUpdate", "Price"],
"orderBy": "Name",
"orderDir": "asc"
},
"columns": [{
"dbField": "Id",
"show": true,
"widthMobile": 90,
"widthPhablet": 89,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "ExtKey",
"show": false,
"widthMobile": 90,
"widthPhablet": 120,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 150,
"widthDesktop": 90,
"widthLargeDesktop": 100
}, {
"dbField": "InsertionDate",
"show": true,
"widthMobile": 90,
"widthPhablet": 100,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 100,
"widthDesktop": 90,
"widthLargeDesktop": 110
}, {
"dbField": "DeletionDate",
"show": false,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 100
}, {
"dbField": "Name",
"show": true,
"widthMobile": 90,
"widthPhablet": 130,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "Address",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "ZipCode",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "EmailAddress",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "PhoneNumber",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "UserName",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "Password",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "LastUpdate",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}, {
"dbField": "Price",
"show": true,
"widthMobile": 90,
"widthPhablet": 90,
"widthMiniTablet": 90,
"widthTablet": 90,
"widthSmallDesktop": 90,
"widthDesktop": 90,
"widthLargeDesktop": 90
}
]
}
正如您所看到的那样,使用stringify不会改变列的顺序。
答案 0 :(得分:0)
我想你必须尝试这样......
var userData = tableWidget.grid('userData');
console.log(tableWidget.grid('userData'));
$.ajax({
url: "../../server/query.aspx?tableEvent=reordercolumns&table=SubContractor",
data: { 'dataColumnOrder': userData},
dataType: "json",
type: "POST",
success:function(response){
//write JS when ajax call success
console.log('success');
},
error: function () {
console.log("Something wrong with the columns' reorder saving process");
}
});