How to update nativescript radlistview with new items at intervals

125 views Asked by At

i'm creating a nativescript core app with radlistview and i would like the listview to add new items automatically at intervals.

if you have any knowledge of how i can achieve this, please help, i would appreciate.

this is my view-model.js

_sourceDataItems: new ObservableArray(),
    dataItems: new ObservableArray(),
    initDataItems: function () {
            var url="example.com";
            fetch(url).then((response) => response.json()).then((res) => {
            var count = res.items.length;
            this._sourceDataItems = res.items;
            this.addMoreItemsFromSource(5);
            }).catch((err) => {

            });
      },
      addMoreItemsFromSource: function (chunkSize) {
        console.log(this._sourceDataItems);
        let newItems = this._sourceDataItems.splice(0, chunkSize);
          this.dataItems.push(newItems);
      },
      
      onLoadMoreItemsRequested: function (args) {
        console.log("---load more item---");
        const that = new WeakRef(this);
        const listView = args.object;
        if (this._sourceDataItems.length > 0) {
          setTimeout(function () {
            that.get().addMoreItemsFromSource(25);
            listView.notifyLoadOnDemandFinished();
          }, 1500);
          args.returnValue = true;
        } else {
          args.returnValue = false;
          listView.notifyLoadOnDemandFinished(true);
        }
      },       
  });
 

if you need anymore info, let me know

0

There are 0 answers