1

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

kunlee
  • 591
  • 1
  • 4
  • 15
  • Are you looking for something more than setInterval()? See https://stackoverflow.com/questions/3138756/calling-a-function-every-60-seconds – David Aug 30 '20 at 14:03
  • @David i don't mind using that, but i'm confused as to where the setInterval() will be placed – kunlee Aug 31 '20 at 00:07
  • It could be in the onNavigatedTo or onLoaded handlers, and then reset in onNavigatingFrom, but it depends on your app and what you want to do. See https://docs.nativescript.org/ui/components/page#page-events – David Aug 31 '20 at 00:41

0 Answers0