diff --git a/source/Ox.UI/js/List/List.js b/source/Ox.UI/js/List/List.js index 046df559..55f16ba3 100644 --- a/source/Ox.UI/js/List/List.js +++ b/source/Ox.UI/js/List/List.js @@ -1834,7 +1834,9 @@ Ox.List = function(options, self) { self.options.items[pos][key] = value; } else if (self.items) { // items array was passed to initialize the list - self.items[Ox.getIndexById(self.items, id)][key] = value; + self.items[ + Ox.getIndex(self.items, self.options.unique, id) + ][key] = value; updateItems = true; } data[key] = value; diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index 693a3f45..348d2cf6 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -494,6 +494,13 @@ Ox.flatten = function(array) { return ret; }; +// FIXME: add docs and tests +Ox.getIndex = function(array, key, value) { + return Ox.indexOf(array, function(obj) { + return obj[key] === value; + }); +}; + /*@ Ox.getIndexById Returns the first array index of an object with a given id (array, id) -> Index (or `-1`) @@ -505,9 +512,13 @@ Ox.getIndexById Returns the first array index of an object with a given id -1 @*/ Ox.getIndexById = function(array, id) { - return Ox.indexOf(array, function(obj) { - return obj.id === id; - }); + return Ox.getIndex(array, 'id', id); +}; + +// FIXME: add docs and tests +Ox.getObject = function(array, key, value) { + var index = Ox.getIndex(array, key, value); + return index > -1 ? array[index] : null; }; /*@ @@ -521,8 +532,7 @@ Ox.getObjectById Returns the first object in an array with a given id null @*/ Ox.getObjectById = function(array, id) { - var index = Ox.getIndexById(array, id); - return index > -1 ? array[index] : null; + return Ox.getObject(array, 'id', id); }; /*