本文整理匯總了TypeScript中tns-core-modules/data/virtual-array.VirtualArray.setItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript VirtualArray.setItem方法的具體用法?TypeScript VirtualArray.setItem怎麽用?TypeScript VirtualArray.setItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tns-core-modules/data/virtual-array.VirtualArray
的用法示例。
在下文中一共展示了VirtualArray.setItem方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentItem = function () {
// >> virtual-array-itemsloading
var array = new virtualArrayModule.VirtualArray<number>(100);
array.loadSize = 15;
// >> (hide)
var result: virtualArrayModule.ChangedData<number>;
var index = 0;
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
result = args;
});
array.setItem(index, 0);
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray<T> setItem() should raise 'change' event with correct args!");
result = undefined;
array.setItem(index, 1);
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray<T> setItem() should raise 'change' event with correct args!");
// << (hide)
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
// Argument (args) is ItemsLoading.
// args.index is start index of the page where the requested index is located.
// args.count number of requested items.
//
// Note: Virtual array will divide total number of items to pages using "loadSize" property value. When you request an
// item at specific index the array will raise "itemsLoading" event with "ItemsLoading" argument index set to the first index of the requested page
// and count set to number of items in this page.
//
// Important: If you have already loaded items in the requested page the array will raise multiple times "itemsLoading" event to request
// all ranges of still not loaded items in this page.
var itemsToLoad = new Array<number>();
for (var i = 0; i < args.count; i++) {
itemsToLoad.push(i + args.index);
}
array.load(args.index, itemsToLoad);
});
// << virtual-array-itemsloading
};
示例2: function
export var test_VirtualArray_shouldRaiseItemsLoadingIfIndexIsNotLoadedAndGetItemIsCalledCorrectNumberOfTimesWithCorrectArgs = function () {
var array = new virtualArrayModule.VirtualArray<number>(100);
array.loadSize = 15;
array.setItem(0, 0);
array.setItem(5, 5);
var result = new Array<virtualArrayModule.ItemsLoading>();
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
result.push(args);
});
array.getItem(1);
TKUnit.assert(result.length === 2 &&
result[0].eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result[0].index === 1 && result[0].count === 4 &&
result[1].eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result[1].index === 6 && result[1].count === 9,
"VirtualArray<T> getItem() should raise 'itemsLoading' event with correct args!");
};