Calling myObservableArray.slice(.) is equivalent to calling the same method on the underlying array (i.e., myObservableArray().slice(.)). The slice function is the observableArray equivalent of the native JavaScript slice function (i.e., it returns the entries of your array from a given start index up to a given end index). For example, myObservableArray.indexOf('Blah') will return the zero-based index of the first array entry that equals Blah, or the value -1 if no matching value was found. The indexOf function returns the index of the first array item that equals your parameter. The rest of this page describes observableArray’s functions for reading and writing array information. For functions that modify the contents of the array, such as push and splice, KO’s methods automatically trigger the dependency tracking mechanism so that all registered listeners are notified of the change, and your UI is automatically updated which means there is a significant difference between using KO’s methods (i.e., observableArray.push(.) ) and JavaScript native array methods (i.e., observableArray().push(.)) as the latter don’t send any notification to the array’s subscribers that its content has changed.(For example, the native JavaScript indexOf function doesn’t work on IE 8 or earlier, but KO’s indexOf works everywhere.) KO’s observableArray has equivalent functions of its own, and they’re more useful because: Technically you can use any of the native JavaScript array functions to operate on that underlying array, but normally there’s a better alternative.
0 Comments
Leave a Reply. |