gpt4 book ai didi

javascript - Knockout.js 排序列表

转载 作者:数据小太阳 更新时间:2023-10-29 05:46:50 25 4
gpt4 key购买 nike

我有一个使用 knockout.js 作为选择列表的排序列表。我想将其转换为无序列表。 knockout.js排序列表的方法是什么?我认为错误在于:allItems().length > 1

http://jsfiddle.net/infatti/Ky5DK/

var BetterListModel = function () {
this.allItems = ko.observableArray([
{ name: 'Denise' },
{ name: 'Charles' },
{ name: 'Bert' }
]); // Initial items

this.sortItems = function() {
this.allItems.sort();
};
};

ko.applyBindings(new BetterListModel());


<button data-bind="click: sortItems, enable: allItems().length > 1">Sort</button>

最佳答案

this.allItems(this.allItems().sort(function(a, b) { return a.name > b.name;}));

关于javascript - Knockout.js 排序列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16744045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com