最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Knockoutjs: How to filter observableArray by param - Stack Overflow

programmeradmin2浏览0评论

Here is the code: /

How to filter personRoles by role property?
Each list must have only own role items.

Thanks.

Here is the code: http://jsfiddle.net/Gr3fT/1/

How to filter personRoles by role property?
Each list must have only own role items.

Thanks.

Share Improve this question asked Nov 10, 2011 at 10:07 Lari13Lari13 1,87010 gold badges28 silver badges56 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 15

This function works (based on 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); 
}

It might help you.

This example basically used for filter observable array by passing input parameters at the key up event.

https://stackoverflow.com/a/25241564/3929314

发布评论

评论列表(0)

  1. 暂无评论