首页 > 解决方案 > 如何删除 nativescript radlistview 中的项目并加载新项目

问题描述

我正在使用radlistview开发一个nativescript项目。当我使用radlistview导航到页面时,它会显示项目。当我离开页面并返回时,它仍然显示以前的项目,而不是重新加载新项目。

请问我怎样才能做到这一点。

这是我用来填充 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) => {

  });

我正在使用 nativescript 核心

标签: nativescriptnativescript-telerik-ui

解决方案


您每次都使用相同的视图模型实例。将您的视图模型创建语句移动到页面加载事件。

const searchViewModel = new SearchViewModel();

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

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

推荐阅读