Ox.IconList: make value method accept (id, {key: value})
This commit is contained in:
parent
5001a47cf8
commit
9d189c55da
1 changed files with 22 additions and 15 deletions
|
@ -251,25 +251,32 @@ Ox.IconList = function(options, self) {
|
||||||
(id) -> <o> get all data for item
|
(id) -> <o> get all data for item
|
||||||
(id, key) -> <s> get value of key of item with id
|
(id, key) -> <s> get value of key of item with id
|
||||||
(id, key, value) -> <f> set value, returns IconList
|
(id, key, value) -> <f> set value, returns IconList
|
||||||
|
(id, {key: value, ...}) -> <f> set values, returns IconList
|
||||||
@*/
|
@*/
|
||||||
that.value = function(id, key, value) {
|
that.value = function() {
|
||||||
// fixme: make this accept id, {k: v, ...}
|
var args = Ox.slice(arguments),
|
||||||
|
id = args.shift(),
|
||||||
|
sort = false;
|
||||||
if (arguments.length == 1) {
|
if (arguments.length == 1) {
|
||||||
return that.$element.value(id);
|
return that.$element.value(id);
|
||||||
} else if (arguments.length == 2) {
|
} else if (arguments.length == 2 && Ox.isString(arguments[1])) {
|
||||||
return that.$element.value(id, key);
|
return that.$element.value(id, arguments[1]);
|
||||||
} else {
|
} else {
|
||||||
|
Ox.forEach(Ox.makeObject(args), function(value, key) {
|
||||||
that.$element.value(id, key, value);
|
that.$element.value(id, key, value);
|
||||||
if (key == self.unique) {
|
if (key == self.unique) {
|
||||||
// unique id has changed
|
// unique id has changed
|
||||||
self.options.selected = self.options.selected.map(function(id_) {
|
self.options.selected = self.options.selected.map(function(id_) {
|
||||||
return id_ == id ? value : id_
|
return id_ == id ? value : id_
|
||||||
});
|
});
|
||||||
|
id = value;
|
||||||
}
|
}
|
||||||
if (key == self.options.sort[0].key) {
|
if (key == self.options.sort[0].key) {
|
||||||
// sort key has changed
|
// sort key has changed
|
||||||
that.$element.sort();
|
sort = true;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
sort && that.$element.sort();
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue