如何在 Nativescript 中重新启动按需加载?

How to restart a Load on demand in Nativescript?

我有一个 Radlistview,其中数据根据用户在日历中选择的日期而变化。

我正在使用 loadOnDemandMode = "Manual",在当前查询用完之前它工作正常。发生这种情况时,我使用 listView.notifyLoadOnDemandFinished (true),但如果用户尝试选择另一天,我将无法再次使用 "Load on Demand"。

我再次尝试实例化 ObservableArray,但它不起作用。如果有人知道如何重新启动按需加载,我将不胜感激

我关注 THIS for create the code, and I tried ,但它对我不起作用。我的代码是这样的

<RadListView [items]="dataItems" 
loadOnDemandMode="Manual" 
(loadMoreDataRequested)="onLoadMoreItemsRequested($event)">
export class ListViewFixedSizeManualComponent implements OnInit {
    private _dataItems: ObservableArray<DataItem>;
    private _sourceDataItems: ObservableArray<DataItem>;
    private layout: ListViewLinearLayout;

    constructor(private _changeDetectionRef: ChangeDetectorRef) {
    }

    ngOnInit() {
        this.layout = new ListViewLinearLayout();
        this.layout.scrollDirection = ListViewScrollDirection.Vertical;
        this.initDataItems();
        this._changeDetectionRef.detectChanges();
        this._dataItems = new ObservableArray<DataItem>();
        this.addMoreItemsFromSource(6);
    }

    public get dataItems(): ObservableArray<DataItem> {
        return this._dataItems;
    }


    public addMoreItemsFromSource(chunkSize: number) {
        let newItems = this._sourceDataItems.splice(0, chunkSize);
        this.dataItems.push(newItems);
    }

    public onLoadMoreItemsRequested(args: LoadOnDemandListViewEventData) {
        const that = new WeakRef(this);
        const listView: RadListView = args.object;
        if (this._sourceDataItems.length > 0) {
            setTimeout(function () {
                that.get().addMoreItemsFromSource(2);
                listView.notifyLoadOnDemandFinished();
            }, 1500);
        } else {
            args.returnValue = false;
            listView.notifyLoadOnDemandFinished(true);
        }
    }

    private initDataItems() {
        this._sourceDataItems = new ObservableArray<DataItem>();
        for (let i = 0; i < posts.names.length; i++) {
            if (androidApplication) {
                this._sourceDataItems.push(new DataItem(i, posts.names[i], "This is item description", posts.titles[i], posts.text[i], "res://" + posts.images[i].toLowerCase()));
            }
            else {
                this._sourceDataItems.push(new DataItem(i, posts.names[i], "This is item description", posts.titles[i], posts.text[i], "res://" + posts.images[i]));
            }
        }
    }
}

我解决了从 listView.notifyLoadOnDemandFinished() 中删除 true 选项并添加选项 ListViewLoadOnDemandMode.None 的问题,所以当我更改日期时,只需要添加 ListViewLoadOnDemandMode.Manual再次

      if (this.getHistoricData.length > 0) {
        setTimeout(function () {
          that.get().addMoreItemsFromSource(10);
          listView.notifyLoadOnDemandFinished();
        }, 1500);
      } else {
        list.listView.loadOnDemandMode = ListViewLoadOnDemandMode.None;
        listView.notifyLoadOnDemandFinished();

参考:nativescript-ui-samples-angular