1

我已经在我的 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.
},

});

4

0 回答 0