gpt4 book ai didi

javascript - 如何删除 KnockOut 分页网格的行?

转载 作者:太空宇宙 更新时间:2023-11-04 15:39:25 26 4
gpt4 key购买 nike

我的观点:

<div data-bind='simpleGrid: gridViewModel'> </div>

<button data-bind='click: addItem'>
Add item
</button>

<button data-bind='click: sortByName'>
Sort by name
</button>

<button data-bind='click: jumpToFirstPage, enable: gridViewModel.currentPageIndex'>
Jump to first page
</button>

我的 View 模型:

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: "Indifferent Monkey", sales: 1, price: 99.95 },
{ 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);

this.addItem = function() {
this.items.push({ name: "New item", sales: 0, price: 100 });
};

this.sortByName = function() {
this.items.sort(function(a, b) {
return a.name < b.name ? -1 : 1;
});
};

this.jumpToFirstPage = function() {
this.gridViewModel.currentPageIndex(0);
};

this.gridViewModel = new ko.simpleGrid.viewModel({
data: this.items,
columns: [
{ headerText: "Item Name", rowText: "name" },
{ headerText: "Sales Count", rowText: "sales" },
{ headerText: "Price", rowText: function (item) { return "$" + item.price.toFixed(2) } }
],
pageSize: 4
});
};

ko.applyBindings(new PagedGridModel(initialData));

这是我的 jsFiddle:http://jsfiddle.net/rniemeyer/QSRBR/

我希望能够删除每一行。我想得到每行删除操作的结尾。我该怎么办?先感谢您。我正在等待你们的答复。

最佳答案

Knockout 组件基于与其关联的数据。

要删除任何行,您只需操作与其关联的数组即可。

Sample JSFiddle .

注意

我刚刚使用了 array.shiftarray.pop 进行演示。您可以查看array.splice以删除中间的任何行。

关于javascript - 如何删除 KnockOut 分页网格的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44017243/

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