本文整理汇总了TypeScript中phosphor/lib/collections/vector.Vector.insert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Vector.insert方法的具体用法?TypeScript Vector.insert怎么用?TypeScript Vector.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phosphor/lib/collections/vector.Vector
的用法示例。
在下文中一共展示了Vector.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addItem
/**
* Add an item to the list at the specified index.
*
* @param index - The index at which to add the item. This must be
* an integer in the range `[0, internal.length]`.
*
* @param item - The item to add at the specified index.
*
* @returns The index at which the item was added.
*
* #### Notes
* This may be reimplemented by subclasses to customize the behavior.
*/
protected addItem(index: number, item: T): number {
this.internal.insert(index, item);
this.changed.emit({
type: 'add',
newIndex: index,
newValue: item,
oldIndex: -1,
oldValue: void 0,
});
return index;
}
示例2: replaceItems
/**
* Replace items at a specific location in the list.
*
* @param index - The index at which to modify the list. This must
* be an integer in the range `[0, internal.length]`.
*
* @param count - The number of items to remove from the list. This
* must be an integer in the range `[0, internal.length]`.
*
* @param items - The items to insert at the specified index.
*
* @returns An array of the items removed from the list.
*
* #### Notes
* This may be reimplemented by subclasses to customize the behavior.
*/
protected replaceItems(index: number, count: number, items: T[]): T[] {
let old: T[] = [];
while (count-- > 0) {
old.push(this.internal.removeAt(index));
}
let i = index;
let j = 0;
let len = items.length;
while (j < len) {
this.internal.insert(i++, items[j++]);
}
this.changed.emit({
type: 'replace',
newIndex: index,
newValue: items,
oldIndex: index,
oldValue: old,
});
return old;
}