Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockoutjs: How to filter observableArray by param

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.

like image 987
Lari13 Avatar asked Nov 10 '11 10:11

Lari13


1 Answers

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); 
}
like image 137
Lari13 Avatar answered Nov 03 '22 18:11

Lari13