add getItem and getItemIndex for List.

This commit is contained in:
Christopher Jeffrey 2014-04-26 01:05:25 -05:00
parent 867dc086a0
commit 44256dcf70
2 changed files with 16 additions and 5 deletions

View File

@ -562,7 +562,7 @@ A scrollable list which can display selectable items.
- inherits all from Box.
- **add/addItem(text)** - add an item based on a string.
- **removeItem(child)** - removes an item from the list. child can be an
element or an index.
element, index, or string.
- **clearItems()** - clears all items from the list.
- **setItems(items)** - sets the list items to multiple strings.
- **select(index)** - select an index of an item.

View File

@ -4209,11 +4209,22 @@ List.prototype.appendItem = function(item) {
}
};
List.prototype.removeItem = function(child) {
var i = typeof child !== 'number'
? this.items.indexOf(child)
: child;
List.prototype.getItemIndex = function(child) {
if (typeof child === 'number') {
return child;
} else if (typeof child === 'string') {
return this.ritems.indexOf(child);
} else {
return this.items.indexOf(child);
}
};
List.prototype.getItem = function(child) {
return this.items[this.getItemIndex(child)];
};
List.prototype.removeItem = function(child) {
var i = this.getItemIndex(child);
if (~i && this.items[i]) {
child = this.items.splice(i, 1)[0];
this.ritems.splice(i, 1);