readysteady
readysteady

Reputation: 324

Troubles with filtering observableArray

I need to create new array, that will contain only items with value "pos" equal to zero or greater. My source array of objects:

self.appendableData = ko.observableArray([
    {text: "some text 1", pos: -1},
    {text: "some text 2", pos: 0},
    {text: "some text 3", pos: 1},
]);

trying to filter it

self.appendableDataToView = ko.computed(function () {
    return ko.utils.arrayFilter(self.appendableData(), function (item) {
        return item.pos >= 0;
    });
});

result: empty array

console.log(self.appendableDataToView())

[];

=(

Upvotes: 0

Views: 32

Answers (1)

Max Brodin
Max Brodin

Reputation: 3938

You need appendableData to be a variable

self.appendableData = ko.observableArray();

instead of

self.appendableData() = ko.observableArray();

Upvotes: 2

Related Questions