Filtrar una matriz de eliminación en función de las entradas
Frecuentes
Visto 688 equipos
0
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>
Modelo de vista eliminatoria:
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);
I am trying to filter an observable array PeopleArray() based on the inputs
1 Respuestas
1
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
});
});
});
Respondido 03 Feb 14, 15:02
It's the logic I am looking for, I need to filter by all four inputs at once. - user3147424
what is the logic in the ko.utils.arrayFilter for all four filters, I want them to be included if they include the filter value - user3147424
I'm not sure what your logic is for your filters. Are you filtering on a string? A value less than another value. You need to fill that logic in. - Mateo
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript html arrays knockout.js ko.observablearray or haz tu propia pregunta.
is there a reason you're not using an observableArray? where are you scripting your valueUpdate bindings? - beauXjames
no reason that I'm not using an observable array, I was originally following the filter in the documentación eliminatoria but I am having problems because I have multiple filters. . . - user3147424
I forgot to add I already have an observable array...i want to return when the first column of the array includes the first input filter, second column of the array includes the second input filter, etc - user3147424