过滤淘汰赛阵列基于投入的 [英] Filter a Knockout Array Based On Inputs
本文介绍了过滤淘汰赛阵列基于投入的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我用来填充表淘汰赛阵列。我也有,我使用数据绑定到过滤数组变量输入。 。 。我需要用这些输入来过滤我的阵列,并只显示该数组....我怎么能做到这一点,我在下面FilteredAray哪里?是。
I have a knockout array that I use to populate a table. I also have inputs that I use to data-bind to a variable in Filtered Array. . .I need to use these inputs to filter my array and only display that array....how can I do this in my FilteredAray below where the ? is.
<td><input data-bind="value: First, valueUpdate: 'afterkeydown'" /></td>
<td><input data-bind="value: Second, valueUpdate: 'afterkeydown'"/></td>
<td><input data-bind="value: Third, valueUpdate: 'afterkeydown'" /></td>
<td><input data-bind="value: Fourth, valueUpdate: 'afterkeydown'"/></td>
淘汰赛视图模型:
Knockout View Model:
self.First = ko.observable('');
self.Second = ko.observable('');
self.Third = ko.observable('');
self.Fourth = ko.observable('');
self.FilteredArray = ko.computed(function () {
var First = self.First();
var Second = self.Second();
var Third = self.Third();
var Fourth = self.Fourth();
? Filter self.PeopleArray()
}, self);
我想筛选基于输入可观察阵列PeopleArray()
I am trying to filter an observable array PeopleArray() based on the inputs
推荐答案
您正在寻找的阵列的过滤器。它返回你只返回true形式的回调,结果一个新的数组。
You're looking for array filter. It returns you a new array with only the results that return true form the callback.
self.array = ko.obserableArray();
self.filter1 = ko.observable();
self.filter2 = ko.observable();
self.filter3 = ko.observable();
self.filter4 = ko.observable();
self.array = ko.observableArray();
self.filteredArray = ko.computed(function () {
return ko.utils.arrayFilter(self.array(), function (item) {
//logic for filter1
//logic for filter2
//logic for filter3
//logic for filter4
//if result matches the filter for return true, if not test next filter
});
});
});
这篇关于过滤淘汰赛阵列基于投入的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文