我使用此代码,检查我的看法所有复选框。
var checked = self.includeAllInSoundscript();
var contents = self.filterContents(self.getFilters());
for (var i = 0; i < contents.length; i++) {
contents[i].includeInSoundscript(checked);
}
return true;
复选框
<input type="checkbox" data-bind="checked: includeInSoundscript" title="sometitle" />
这是内容是什么:
(function (ko) {
ContentViewModel = function (data) {
this.orderId = data.orderId;
this.contentReferenceId = ko.observable(data.contentReferenceId);
this.includeInSoundscript = ko.observable();
});
这是过滤器的方法:
self.getFilters = function() {
var filterOrders = $.grep(self.orders(), function (order) {
return (order.usedInfilter());
});
var filterLocations = $.grep(self.locations(), function (location) {
return (location.usedInfilter());
});
return { orders: filterOrders, locations: filterLocations };
};
self.filterContents = function (filter) {
var filteredArray = self.contents();
if (filter.orders.length > 0) {
filteredArray = $.grep(filteredArray, function (content) {
return $.grep(filter.orders, function (order) {
return (order.orderId == content.orderId);
}).length > 0;
});
}
if (filter.locations.length > 0) {
filteredArray = $.grep(filteredArray, function (content) {
return $.grep(filter.locations, function (location) {
return $.inArray(location.location, content.orderedFrom().split('/')) != -1;
}).length > 0;
});
}
return filteredArray;
};
检查所有复选框是快速的,但是当我取消,可能需要长达20秒。 奇怪的是,当filetered结果是小,但它仍然需要更长的时间,即使过滤后的结果为约40%,从总集的1000。
该复选框是在表中,使用数据绑定绑定=“的foreach:内容”
我现在已经删除了一些“unescessary”可观的,因为这极有可能不会改变性质,则表现略好,但仍然很慢,尤其是在Firefox浏览器。 最大的问题是,为什么这种行为只有在取消选中复选框,而不是筛选,排序,检查等。
注意:它只有取消选中的复选框,基本上在“检查”是假的,否则它的快。
编辑:我每次只显示50个项目,但我选中/取消选中所有过滤项目。 这一点,所以,我在CONTROLL张贴到服务器的内容。