2
我加入了以下篩選到我的視圖模型:淘汰賽過濾
contactsViewModel.filterItems = ko.computed(function() {
var filter = this.filterInput().toLowerCase();
if (!filter || !this.hasEnoughChars()) {
// Simply keep the results if input is empty or less 3 chars are in it
return this.contacts();
} else {
// iterate through the JSON again
return ko.utils.arrayFilter(this.contacts(), function (item) {
// Return the objects that contain the filter term
// ko.utils.stringContains is not part of knockout
// Manually added to knockout-2.2.0.debug.js line 238
return ko.utils.stringContains(item.firstName().toLowerCase(), filter)
|| ko.utils.stringContains(item.lastName().toLowerCase(), filter)
|| ko.utils.stringContains(item.email().toLowerCase(), filter)
|| ko.utils.stringContains(item.company().toLowerCase(), filter);
});
}
}, contactsViewModel);
我如何通過減少的時候,我打電話stringContains數量來提高這個代碼? 我想能寫:
return ko.utils.stringContains(item.FirstName().toLowerCase() || item.lastName().toLowerCase() || item.email().toLowerCase() || item.company().toLowerCase(), filter);
但是當我做這個
從淘汰賽stringContains不返回正確的值:
stringContains: function (string, contains) {
string = string || "";
return string.indexOf(contains) != -1;
}
你的幫助是多少讚賞