我在kendoui observable中声明了一个内容数组,但是我如何在add函数中对它进行排序。这是我的代码。
var cart = kendo.observable({
contents: [],
cleared: false,
contentsCount: function () {
return this.get("contents").length;
},
isEmpty: function () {
return (this.get("contents").length == 0);
},
add: function (item) {
var found = false;
this.set("cleared", false);
for (var i = 0; i < this.contents.length; i++) {
var current = this.contents[i];
if (current.item.id == item.id) {
current.set("quantity", current.get("quantity") + 1);
found = true;
break;
}
}
if (!found) {
this.contents.push({ item: item, quantity: 1 });
}
// I NEED TO SORT THE ARRAY HERE.
},
});