Sim*_*mon 9 asp.net-mvc-4 knockout.js
我对我的模型有所了解:
self.filteredItems = ko.computed(function () {
var filter = this.filter().toLowerCase();
if (!filter) {
return this.sites();
} else {
return ko.utils.arrayFilter(this.sites(), function (item) {
return ko.utils.stringStartsWith(item.Name().toLowerCase(), filter);
});
}
}, self);
Run Code Online (Sandbox Code Playgroud)
我用它来搜索我的页面而不是stringStartsWith我想要某种类型的.contains,所以我得到的结果是我的searchterm包含在字符串中的任何地方而不是仅仅在开头.
我想这必须是一个非常常见的请求,但是找不到任何明显的东西.
有什么建议吗?
nem*_*esv 14
您可以使用简单的string.indexOf方法来检查"字符串包含":
self.filteredItems = ko.computed(function () {
var filter = this.filter().toLowerCase();
if (!filter) {
return this.sites();
} else {
return ko.utils.arrayFilter(this.sites(), function (item) {
return item.Name().toLowerCase().indexOf(filter) !== -1;
});
}
}, self);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7302 次 |
| 最近记录: |