想要从 KoObservableArray 中删除重复值。我有以下 JS 文件。我想将 UI 中的名称列绑定为下拉列表以及删除重复值。
建议最好的方法来做同样的事情。
JS文件
$(function () {
var initialData = [
{ name: "Well-Travelled Kitten", sales: 352, price: 75.95 },
{ name: "Speedy Coyote", sales: 89, price: 190.00 },
{ name: "Furious Lizard", sales: 152, price: 25.00 },
{ name: "Furious Lizard", sales: 213, price: 25.00 },
{ name: "Indifferent Monkey", sales: 1, price: 99.95 },
{ name: "Speedy Coyote", sales: 89, price: 190.00 },
{ name: "Brooding Dragon", sales: 0, price: 6350 },
{ name: "Ingenious Tadpole", sales: 39450, price: 0.35 },
{ name: "Optimistic Snail", sales: 420, price: 1.50 }
];
var PagedGridModel = function (items) {
this.items = ko.observableArray(items);
};
ko.applyBindings(new PagedGridModel(initialData));
});
HTML File
<body>
<nav>
<label for="name">Name</label>
<select id="name" data-bind="options: items, optionsText: 'name', optionsCaption:'All'">
</select>
</nav>
</body>
以上给了我重复名称的下拉列表。