Ox.List: use Ox.contains
This commit is contained in:
parent
cdf8aa8788
commit
4b84424869
1 changed files with 7 additions and 7 deletions
|
@ -219,7 +219,7 @@ Ox.List = function(options, self) {
|
||||||
self.selected = self.options.items.map(function(item, i) {
|
self.selected = self.options.items.map(function(item, i) {
|
||||||
return Ox.extend(item, {_index: i})
|
return Ox.extend(item, {_index: i})
|
||||||
}).filter(function(item) {
|
}).filter(function(item) {
|
||||||
return self.options.selected.indexOf(item[self.options.unique]) > -1;
|
return Ox.contains(self.options.selected, item[self.options.unique]);
|
||||||
}).map(function(item) {
|
}).map(function(item) {
|
||||||
return item['_index'];
|
return item['_index'];
|
||||||
});
|
});
|
||||||
|
@ -765,7 +765,7 @@ Ox.List = function(options, self) {
|
||||||
var ids = [], rest = [],
|
var ids = [], rest = [],
|
||||||
useRest = self.selected.length > self.listLength / 2;
|
useRest = self.selected.length > self.listLength / 2;
|
||||||
result.data.items.forEach(function(item, i) {
|
result.data.items.forEach(function(item, i) {
|
||||||
if (self.selected.indexOf(i) > -1) {
|
if (isSelected(i)) {
|
||||||
ids.push(item[self.options.unique]);
|
ids.push(item[self.options.unique]);
|
||||||
} else if (useRest) {
|
} else if (useRest) {
|
||||||
rest.push(item[self.options.unique]);
|
rest.push(item[self.options.unique]);
|
||||||
|
@ -787,7 +787,7 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSelected(pos) {
|
function isSelected(pos) {
|
||||||
return self.selected.indexOf(pos) > -1;
|
return Ox.contains(self.selected, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSpecialTarget(e) {
|
function isSpecialTarget(e) {
|
||||||
|
@ -1463,7 +1463,7 @@ Ox.List = function(options, self) {
|
||||||
getSelectedIds(function(oldIds) {
|
getSelectedIds(function(oldIds) {
|
||||||
var newIds = [];
|
var newIds = [];
|
||||||
Ox.forEach(self.options.items, function(item) {
|
Ox.forEach(self.options.items, function(item) {
|
||||||
if (oldIds.indexOf(item.id) > -1) {
|
if (Ox.contains(oldIds, item.id)) {
|
||||||
newIds.push(item.id);
|
newIds.push(item.id);
|
||||||
}
|
}
|
||||||
if (newIds.length == oldIds.length) {
|
if (newIds.length == oldIds.length) {
|
||||||
|
@ -1508,7 +1508,7 @@ Ox.List = function(options, self) {
|
||||||
if (selectedIds.length) {
|
if (selectedIds.length) {
|
||||||
self.selected = [];
|
self.selected = [];
|
||||||
self.options.items.forEach(function(item, i) {
|
self.options.items.forEach(function(item, i) {
|
||||||
if (selectedIds.indexOf(item.id) > -1) {
|
if (Ox.contains(selectedIds, item.id)) {
|
||||||
self.selected.push(i);
|
self.selected.push(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1681,7 +1681,7 @@ Ox.List = function(options, self) {
|
||||||
});
|
});
|
||||||
} else { // remove items from pos to pos+length
|
} else { // remove items from pos to pos+length
|
||||||
Ox.range(pos, pos + length).forEach(function(i) {
|
Ox.range(pos, pos + length).forEach(function(i) {
|
||||||
self.selected.indexOf(i) > -1 && deselect(i);
|
isSelected(i) && deselect(i);
|
||||||
self.$items[i].remove();
|
self.$items[i].remove();
|
||||||
});
|
});
|
||||||
self.options.items.splice(pos, length);
|
self.options.items.splice(pos, length);
|
||||||
|
@ -1744,7 +1744,7 @@ Ox.List = function(options, self) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
size <f> fixme: not a good function name
|
size <f> Update list size
|
||||||
() -> <o> List Object
|
() -> <o> List Object
|
||||||
@*/
|
@*/
|
||||||
that.size = function() { // fixme: not a good function name
|
that.size = function() { // fixme: not a good function name
|
||||||
|
|
Loading…
Reference in a new issue