Ox.List: make value method accept (id, {key: value})
This commit is contained in:
parent
41af852f17
commit
a5baff8319
1 changed files with 20 additions and 17 deletions
|
@ -1794,34 +1794,37 @@ Ox.List = function(options, self) {
|
|||
|
||||
/*@
|
||||
value <f> get/set list value
|
||||
(id, {key: value, ...}) -> <f> sets value, returns List Element
|
||||
(id, key, value) -> <f> sets value, returns List Element
|
||||
(id, key) -> <a> returns value
|
||||
(id) -> <o> returns all values of id
|
||||
id <s> id of item
|
||||
id <s|n> id of item (or a number, will be interpreted as position)
|
||||
key <s> key if item property
|
||||
value <*> value, can be whatever that property is
|
||||
@*/
|
||||
// FIXME: this should accept {key: value, ...} too
|
||||
that.value = function(id, key, value) {
|
||||
// id can be a number and will then be interpreted as position
|
||||
var pos = Ox.isNumber(id) ? id : getPositionById(id),
|
||||
that.value = function() {
|
||||
var args = Ox.slice(arguments),
|
||||
id = args.shift(),
|
||||
pos = Ox.isNumber(id) ? id : getPositionById(id),
|
||||
$item = self.$items[pos],
|
||||
data = $item ? $item.options('data') : {};
|
||||
if (arguments.length == 1) {
|
||||
return data;
|
||||
} else if (arguments.length == 2) {
|
||||
return data[key];
|
||||
} else if (arguments.length == 2 && Ox.isString(arguments[1])) {
|
||||
return data[arguments[1]];
|
||||
} else if ($item) {
|
||||
if (key == self.options.unique) {
|
||||
// unique id has changed
|
||||
self.options.selected = self.options.selected.map(function(id_) {
|
||||
return id_ == data[key] ? value : id_
|
||||
});
|
||||
}
|
||||
if (!self.isAsync) {
|
||||
self.options.items[pos][key] = value;
|
||||
}
|
||||
data[key] = value;
|
||||
Ox.forEach(Ox.makeObject(args), function(value, key) {
|
||||
if (key == self.options.unique) {
|
||||
// unique id has changed
|
||||
self.options.selected = self.options.selected.map(function(id_) {
|
||||
return id_ == data[key] ? value : id_
|
||||
});
|
||||
}
|
||||
if (!self.isAsync) {
|
||||
self.options.items[pos][key] = value;
|
||||
}
|
||||
data[key] = value;
|
||||
});
|
||||
$item.options({data: data});
|
||||
return that;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue