Javascript Knockoutjs:如何通过参数过滤 observableArray
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8077822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Knockoutjs: How to filter observableArray by param
提问by Lari13
Here is the code: http://jsfiddle.net/Gr3fT/1/
这是代码:http: //jsfiddle.net/Gr3fT/1/
How to filter personRoles
by role
property?
Each list must have only own role
items.
如何personRoles
按role
属性过滤?
每个列表必须只有自己的role
项目。
Thanks.
谢谢。
回答by Lari13
This function works (based on http://knockoutjs.com/examples/animatedTransitions.html:)
此功能有效(基于http://knockoutjs.com/examples/animatedTransitions.html:)
get: function(role)
{
return ko.dependentObservable(function ()
{
return ko.utils.arrayFilter(this.personRoles(), function(item)
{
return item.id == role;
});
}, viewModel);
}
回答by user3929314
It might help you.
它可能会帮助你。
This example basically used for filter observable array by passing input parameters at the key up event.
这个例子主要用于通过在 key up 事件中传递输入参数来过滤 observable 数组。