Lari13
Lari13

Reputation: 1870

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.

Upvotes: 11

Views: 21450

Answers (2)

user3929314
user3929314

Reputation: 1

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

Upvotes: 0

Lari13
Lari13

Reputation: 1870

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); 
}

Upvotes: 15

Related Questions