我正在使用RadListView,并有一个使用loadOnDemand加载更多的图像列表。每隔一段时间我就会在Android上收到一个令人讨厌的错误,上面写着Cannot read property 'picture' of undefined
,它会冻结整个应用程序一段时间。
令人沮丧的是因为我一直认为我会在一段时间没有发生时修复它,但随后会随机回来。我认为一个完整的项目重构可能会解决问题,但事实并非如此。
我创建了一个有问题的示例项目。 https://github.com/keerl/radlistview-bug。
我还为它创建了一个游乐场:https://play.nativescript.org/?id=H7lJuH&template=play-ng&v=3
我还录制了一个发生问题的视频。 https://www.youtube.com/watch?v=_EGvw8REek8。问题是非常随机的,有时它永远不会触发(这让我觉得我修复了它),然后几个小时后再开始发生。只在Android上发生。我已经尝试使用插件进行图像缓存(WebImage),认为图像加载导致问题,也许占位符会有所帮助,但这并没有解决它。
我已经为你更新了playground。你太早地通知了notifyPullToRefreshFinished
的名单。
您只应在数据加载时通知。
loadProducts(PullToRefreshInitiated: boolean) {
return new Promise((resolve, reject) => {
http.getJSON("https://randomuser.me/api/?results=25&inc=picture").then((r) => {
this.users$.push(r.results);
if (PullToRefreshInitiated) {
this.listView.notifyPullToRefreshFinished();
}
// Load a max of 50 items and then force a pull-to-refresh to get more data.
if (this.users$.length > 50) {
resolve(true);
}
else {
resolve(false);
}
}, (e) => {
console.log(e)
});
});
}
附:还有两个建议,我个人在类似的环境中实现。