当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript virtual-array.VirtualArray类代码示例

本文整理汇总了TypeScript中tns-core-modules/data/virtual-array.VirtualArray的典型用法代码示例。如果您正苦于以下问题:TypeScript VirtualArray类的具体用法?TypeScript VirtualArray怎么用?TypeScript VirtualArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VirtualArray类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = function () {
    // >> virtual-array-change
    var array = new virtualArrayModule.VirtualArray<number>(100);
    array.loadSize = 15;

    // >> (hide)
    var result: virtualArrayModule.ChangedData<number>;
    var index = 0;
    // << (hide)

    array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
        // Argument (args) is ChangedData<T>.
        // args.eventName is "change".
        // args.action is "update".
        // args.removed.length and result.addedCount are equal to number of loaded items with load() method.

        // >> (hide)
        result = args;
        // << (hide)
    });

    var itemsToLoad = [0, 1, 2];

    array.load(index, itemsToLoad);
    // << virtual-array-change

    TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
        result.removed.length === itemsToLoad.length && result.index === index && result.addedCount === itemsToLoad.length,
        "VirtualArray<T> load() should raise 'change' event with correct args!");
};
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:30,代码来源:virtual-array-tests.ts

示例2: function

export var test_VirtualArray_shouldNotRaiseItemsLoadingIfIndexIsLoadedAndGetItemIsCalled = function () {
    var array = new virtualArrayModule.VirtualArray<number>(100);
    array.setItem(0, 0);
    array.loadSize = 15;

    var result: virtualArrayModule.ItemsLoading;

    array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
        result = args;
    });

    array.getItem(0);

    TKUnit.assert(types.isUndefined(result), "VirtualArray<T> getItem() should not raise 'itemsLoading' event if item is loaded!");
};
开发者ID:m-abs,项目名称:NativeScript,代码行数:15,代码来源:virtual-array-tests.ts

示例3:

    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);
    });
开发者ID:m-abs,项目名称:NativeScript,代码行数:19,代码来源:virtual-array-tests.ts


注:本文中的tns-core-modules/data/virtual-array.VirtualArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。