Reputation: 1681
Can anybody tell me where my dependent observable is going wrong?
self.FirstTwo = ko.computed(function() {
return self.FiveFave.FaveItems[0].Name + " " + self.FiveFave.FaveItems[1].Name;
}, self);
I just want to concatenate the first two items of an array.
Upvotes: 0
Views: 51
Reputation: 114792
To retrieve the value of an observable, you need to call it as a function with no arguments. In your case, Name
is an observable, so you would have to do:
return self.FiveFave.FaveItems[0].Name() + " " + self.FiveFave.FaveItems[1].Name();
In bindings, where you are passing a simple observable, Knockout handles unwrapping it for you, which is why you don't have to do things like text: name()
Upvotes: 1