Search code examples
nativescriptnativescript-telerik-ui

How can i delete items in nativescript radlistview and load new ones


i'm working on a nativescript project with radlistview. when i navigate to the page with the radlistview, it shows the items. when i leave the page and go back, instead of reloading new items, it still shows the previous items.

how can i achieve this please.

this is the code i use to populate the radlistview

fetch("https://example.com/skog/searchResults.php?search=" + searchedSkill).then((response) => response.json()).then((res) => {
       viewModel.set("items", res.items);
        viewModel.set("isBusy", false);

   }).catch((err) => {

  });

i'm using nativescript core


Solution

  • You are using the same view model instance every time. Move your view model creation statement to page loaded event.

    From

    const searchViewModel = new SearchViewModel();
    
    exports.pageLoaded = function (args) {
        const page = args.object;
        page.bindingContext = searchViewModel;
        ...
    }
    

    To

    exports.pageLoaded = function (args) {
        const page = args.object;
        page.bindingContext = new SearchViewModel();
        ...
    }