I\'m trying to replace all of the contents of an item in an observableArray
with new content.
var oldLocation = ko.utils.arrayFirst(self.locations()
I simply want to mention an alternative way to do it:
self.locations.splice(
self.locations.indexOf(location), // Index of the 1st element to remove
1, // Number of elements to remote at this index
new fizi.ko.models.location(value) // A param for each element to add at the index
);
Knockout includes splice
in its documentation, but doesn't include replace
: Knockout Obervable Arrays Docs. However, if you look at the source code you'll see that both functions are implemented (at least in KO 3.0, I don't know if replace
was missing in previous versions).