I am trying to implement a simple 'toString' function for an observableArray.
When using this code which seems the most appropriate to me
var viewModel = {
name: ko.observable('test'),
arr: ko.observableArray(['item1']),
third: ko.computed(function(){
return this.arr().join();
})
};
ko.applyBindings(viewModel);
I get a this.arr is not a function error
Why is this happening?
If I run it like this everything is ok.
var viewModel = {
name: ko.observable('test'),
arr: ko.observableArray(['item1']),
third: function(){
return this.arr().join();
}
};
ko.applyBindings(viewModel);
If I use the second approach, will I get the correct arr contents? Does the third variable get updated every time an item is added/removed from arr?