0

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

我正在使用loadOnDemandMode = "Manual"它,它工作正常,直到当前查询用完。发生这种情况时,我会使用listView.notifyLoadOnDemandFinished (true),但如果用户尝试选择另一天,我将无法再次使用“按需加载”。

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

我按照THIS创建代码,我尝试了THIS,但它对我不起作用。我的代码是这样的

<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]));
            }
        }
    }
}
4

1 回答 1

1

我解决了从选项中删除true选项listView.notifyLoadOnDemandFinished()并添加选项的问题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

于 2019-10-01T00:33:33.513 回答