-2

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

kunlee
  • 591
  • 1
  • 4
  • 15
  • Depends on when / where you are loading the data, how you are handling data model. Can you share the complete or possibly a Playground sample? – Manoj Apr 16 '20 at 09:51
  • @Manoj [link](https://play.nativescript.org/?template=play-js&id=fJrbV3&v=141) i load the data on the searchresults page with the variable stored in appSettings by the home page – kunlee Apr 16 '20 at 10:54
  • Please share a minimal sample that focuses on the problem alone, its hard to debug through your whole project. – Manoj Apr 16 '20 at 11:55
  • @Manoj sorry about that, i created a simplified one [link](https://play.nativescript.org/?template=play-js&id=4LhiUD) – kunlee Apr 16 '20 at 13:20

1 Answers1

0

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();
    ...
}
Manoj
  • 21,753
  • 3
  • 20
  • 41