nativescript - 如何删除 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 核心
解决方案
您每次都使用相同的视图模型实例。将您的视图模型创建语句移动到页面加载事件。
从
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();
...
}
推荐阅读
- java - Java 中的 PriorityQueue 实现,支持 changePriority 操作
- apache-spark - 为什么在 k8s 平台上使用 statefulset 部署 spark 而不是正常部署?
- c# - 当成员使用 JsonConvert 反序列化两次时如何引发异常
- electron - 如何在 Electron 中播放自定义声音
- swift - NSManagedObject 约束与 Codable
- c# - 在 ItemTemplate 中绑定 ListView 项目本身
- react-native - 将从 api 调用接收到的数据存储在 react native 中
- ssas - 无法在 SSAS 钻取操作 SSAS 2012 中执行 ASSP 过程
- java - 为什么将字符“�”保存到文件中会保存为“?”?
- ios - UIContextualAction 不在 iOS 12.4 上显示图像,该代码适用于 iOS 13.4