我正在开发一个项目,我们使用KENDOUI作为前端,使用jQuery/Javascript编码来管理任何我们无法做到的事情与框架本身。什么是“.toJSON”以及如何“撤消”或“反向”它
我有剑道电网这就需要客户端排序,这里是我想做的事 -
var tPositiondata = _DetailsGridDS.data();
// sort position datasource in order to bind treeview
tPositiondata = tPositiondata.toJSON().sort(function (a, b) {
{
if ((a.DisplayText.localeCompare(b.DisplayText)) < 0) { return -1; }
else if ((a.DisplayText.localeCompare(b.DisplayText)) > 0) { return 1; }
}
});
//re-initialize the grid with new datasource
$("#DivDetailsTable").empty();
$("#DivDetailsTable").kendoGrid({
autobind: false,
scrollable: true,
height: 333,
pageSize: 10,
dataSource: tPositiondata,
dataBound: OnReceivedDataFromDatasource,
columns: [
{
field: "UniqueValue",
title: _ColumnHeaderUniqueValue
},
{
//field: "DisplayTextTranslation",
title: _ColumnHeaderDisplayText,
template: '#= GetTranslation(Id) #'
},
{
field: "CodeAttribute",
title: _ColumnHeaderCodeAttribute
},
{ command: [{ text: _ButtonEdit, className: "k-button k-button-icontext buttonEdit k-grid-Edit" }, { text: _ButtonDelete, className: "k-button k-button-icontext buttonDelete k-grid-Delete" }, { text: " ", className: "buttonUp", width: 15 }, { text: " ", className: "buttonDown", width: 15}], text: "", title: " ", width: 230 }
],
editable: "inline"
});
现在麻烦的是,变量“tPositionData”不能被重新分配到“_DetailsGridDS “因为它们显然不是同一类型或格式。正因为如此,我的全局变量“_DetailsGridDS”没有更新后的排序数据。如果我在代码中的其他地方引用它,那么我没有对数据进行排序。
有人可以帮我在排序后“撤消”/“反向”.toJSON调用,以便我可以重新分配给_DetailsGridDS,或者可以有人提出解决方法,以便我的全局变量总是更新与最新的排序数据?
http://api.jquery.com/jQuery.parseJSON/应该工作 –
为什么'toJSON()'在那个代码中呢? 'tPositiondata.toJSON()。sort()'没有意义,你不能排序字符串。首先排序,然后使用'toJSON()':'tPositiondata.sort(/ *您的排序函数* /)。toJSON()'。还要注意,如果两个项目相等,你的排序函数应该返回0。 – nnnnnn
TiesonT。 - nopes它不工作,我得到一个空值:| @nnnnnn:我试过,之前我得到一个错误,说[对象对象]没有一种方法称为“排序” – Sandeep