Ox.api: update(items) signature is better (allows for add/remove); Ox.List: update accordingly

This commit is contained in:
rolux 2014-04-30 13:39:14 +02:00
parent 777fbc2a37
commit c26a13b2f1
2 changed files with 9 additions and 8 deletions

View file

@ -1819,14 +1819,14 @@ Ox.List = function(options, self) {
id = args.shift(),
pos = Ox.isNumber(id) ? id : getPositionById(id),
$item = self.$items[pos],
data = $item ? $item.options('data') : {};
data = $item ? $item.options('data') : {},
updateItems = false;
if (arguments.length == 1) {
return data;
} else if (arguments.length == 2 && Ox.isString(arguments[1])) {
return data[arguments[1]];
} else if ($item) {
Ox.forEach(Ox.makeObject(args), function(value, key) {
var index;
if (key == self.options.unique) {
// unique id has changed
self.options.selected = self.options.selected.map(function(id_) {
@ -1837,13 +1837,15 @@ Ox.List = function(options, self) {
self.options.items[pos][key] = value;
} else if (self.items) {
// items array was passed to initialize the list
index = Ox.getIndexById(self.items, id);
self.items[index][key] = value;
self.options.items.update(index, self.items[index]);
self.items[Ox.getIndexById(self.items, id)][key] = value;
updateItems = true;
}
data[key] = value;
});
$item.options({data: data});
if (updateItems) {
self.options.items.update(self.items);
}
return that;
}
};

View file

@ -306,11 +306,10 @@ Ox.api = function(items, options) {
ret = Ox.extend(
api.cache ? Ox.cache(fn, {async: true}) : fn,
{
update: function(index, item) {
items[index] = item;
update: function(updatedItems) {
items = updatedItems;
api.cache && ret.clear();
sortBy.clear();
return items;
}
}
),