这可能不是问题,但这是从头开始学习 native 脚本时出现的一系列疑问。
我有一个 1000 或更多的数据列表存储在数据表中。我知道我想在 ListView 中显示它,但我不想一次读取所有数据。因为我将图像存储在其他目录中并且也想阅读它。所以,对于 20 到 30 个数据的性能是相当不错的。但是对于 1000 个数据,读取数据以及与之相关的图像需要超过 15 分钟的时间。因为我正在存储一些高质量的图像。
因此我决定只读取 20 个数据及其各自的图像。并将其显示在列表中。知道用户何时到达列表的第 15 个数据。我决定从服务器再读取 10 个数据。
知道当我搜索这个时我遇到了“RadListView 按需加载”。 然后我只看了下面的代码。
public addMoreItemsFromSource(chunkSize: number) {
let newItems = this._sourceDataItems.splice(0, chunkSize);
this.dataItems.push(newItems);
}
public onLoadMoreItemsRequested(args: LoadOnDemandListViewEventData) {
const that = new WeakRef(this);
const listView: RadListView = args.object;
if (this._sourceDataItems.length > 0) {
setTimeout(function () {
that.get().addMoreItemsFromSource(2);
listView.notifyLoadOnDemandFinished();
}, 1500);
args.returnValue = true;
} else {
args.returnValue = false;
listView.notifyLoadOnDemandFinished(true);
}
}
在 nativescript 中,如果我想访问绑定(bind)元素 xml 元素。我必须在 viewmodel 中使用 observables 或在关联的 js 文件中使用 exports.com_name。
但在这个例子中它是从 public.. 开始的!如何在 javascript 中使用它。
什么是 new WeakRef(this) ? 为什么需要它?
如何识别用户已经滚动到第 15 个数据,因为我想在他到达第 15 个数据时加载更多数据。
获取数据后如何更新列表数组并在 ListView 中显示?
Finally i just want to know how to use load on demand
我试图创建一个我尝试过的 Playground 样本,但它给出了错误。它找不到 radlistview 的模块。
请记住我是新手 所以,请在回答时记住这一点。谢谢,
如果您觉得不符合标准,请修改问题。
最佳答案
您可以在此处查看更新后的答案 https://play.nativescript.org/?template=play-js&id=1Xireo
关于nativescript - nativescript radlist View 按需加载的工作原理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56824342/