I’ve got a viewmodel that looks like this:
var viewModel = {
name: results.name,
members: ko.observableArray([]),
users: ko.computed(function () {
return ko.utils.arrayFilter(members(), function (item) {
return (item.type == 'User');
});
}),
groups: ko.computed(function () {
return ko.utils.arrayFilter(members(), function (item) {
return (item.type == 'Group');
});
})
};
However, I’m getting an error on the computed part:
Uncaught ReferenceError: members is not defined
Which is true- at the time the viewModel is declared, members contains nothing.
How can I overcome this?
If by
members()you mean the second property on your object:Note that:
You cannot reference another property of the same object inside a literal definition. That’s why I split the definition into 3 parts.
members()was replaced withviewModel.members().