如何在Nativescript Listview中加载数据时触发事件
我已经阅读了这里的文档,但我不知道如何在数据开始或完成加载时将事件绑定到listview。我想知道何时显示/隐藏页面加载图形。我现在使用setimeout,但这并不理想,因为当连接速度快时,加载程序仍然显示不需要的加载程序,而当连接速度慢时,则相反如何在Nativescript Listview中加载数据时触发事件,listview,nativescript,Listview,Nativescript,我已经阅读了这里的文档,但我不知道如何在数据开始或完成加载时将事件绑定到listview。我想知道何时显示/隐藏页面加载图形。我现在使用setimeout,但这并不理想,因为当连接速度快时,加载程序仍然显示不需要的加载程序,而当连接速度慢时,则相反 exports.pageLoadedRequest = () => { loadingIndicator.show(); setTimeout(()=>{ welcomeViewModel.empty("all"); we
exports.pageLoadedRequest = () => {
loadingIndicator.show();
setTimeout(()=>{
welcomeViewModel.empty("all");
welcomeViewModel.getExposuresData({onNavigatingTo:true}).then((response)=>{
const month1 = page.getViewById("month1");
const month2 = page.getViewById("month2");
const month3 = page.getViewById("month3");
const month4 = page.getViewById("month4");
const tabs = page.getViewById("tabs");
//update view elements and bindingcontext
month1.text = response.monthNames._array[0];
month2.text = response.monthNames._array[1];
month3.text = response.monthNames._array[2];
month4.text = response.monthNames._array[3];
tabs.selectedIndex=response.autoSelectedIndex;
previouslyTappedItem = response.autoSelectedIndex + 1;
page.bindingContext = response;
//run the counter now
welcomeViewModel.getRefreshCount({onNavigatingTo:true});
});
setTimeout(()=>{
loadingIndicator.hide();
onNavigatingTo = false;
},5000);
},50)
}
我知道有更好的办法。有人能给我指出正确的方向吗?您指的是在滚动结束时按需加载数据,我认为您应该使用RadListView来实现此目的-不,我不是指在滚动结束时加载nw数据。我选择listview而不是radlistview,因为radlistview对于我所需要的东西来说是一种过度的杀伤力。此外,我的应用程序需要包含四个选项卡的选项卡组件。每个选项卡都有一个列表视图。我读到listview在内存方面更经济,所以我选择了它。我只是想要一种更好的方式来显示/隐藏loadingIndicator,而不使用settimeout。我想挂接到一个事件中,该事件可以告诉我,每当调用获取列表视图的新数据时,数据何时到达或加载。呈现列表应该是即时的,您只需在获取远程数据时显示/隐藏加载指示器。您可以在http请求响应时隐藏指示符。