mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-10 19:16:20 +00:00
add getItem and getItemIndex for List.
This commit is contained in:
parent
867dc086a0
commit
44256dcf70
@ -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.
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user