Implementing the remove() Method

If you need the ability to delete an item from a data source then you need to implement the remove() method. The key of the item being removed is passed to the method and the method returns nothing if the item is removed.

Here’s some sample code that removes an item from an array:

remove: function (key) {    var i = this._getIndexFromKey(key);    this._arrayData.splice(i, 1);    return WinJS.Promise.wrap(null);},_getIndexFromKey:function(key) {    for (var i = 0; i < this._arrayData.length; i++) {        if (this._arrayData[i].key == key) {            return i;        }    }}

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.