Nativescript 当属性为“时,选项卡视图不更新UI”;项目“;变了
在我的项目中,我以编程方式创建了一个TabView,并希望每当我设置Nativescript 当属性为“时,选项卡视图不更新UI”;项目“;变了,nativescript,tabview,Nativescript,Tabview,在我的项目中,我以编程方式创建了一个TabView,并希望每当我设置myTabView.items=newArray时,它都会更新其TabViewItem(例如更改标题)。不幸的是,它不是那样工作的。任何帮助都将不胜感激 以下是生成选项卡视图时的代码: function initTabview(tabList: Array<string>) { let items = []; let myTabView = page.getViewById("myTabView");
myTabView.items=newArray
时,它都会更新其TabViewItem(例如更改标题)。不幸的是,它不是那样工作的。任何帮助都将不胜感激
以下是生成选项卡视图时的代码:
function initTabview(tabList: Array<string>) {
let items = [];
let myTabView = page.getViewById("myTabView");
for (let i in tabList) {
let stackLayout = new StackLayout();
let tabEntry = {
title: tabList[i],
view: stackLayout
};
items.push(tabEntry);
}
myTabView.items = items;
myTabView.on(TabView.selectedIndexChangedEvent, (data: SelectedIndexChangedEventData) => {
// Some code here
});
}
函数initTabview(tabList:Array){
设项目=[];
让myTabView=page.getViewById(“myTabView”);
为了(让我加入小报){
设stackLayout=新建stackLayout();
设tabEntry={
标题:小报作者[i],
视图:堆栈布局
};
items.push(tabEntry);
}
myTabView.items=项目;
myTabView.on(TabView.selectedIndexChangedEvent)(数据:SelectedIndexChangedEventData)=>{
//这里有一些代码
});
}
非常感谢。您好,我认为您应该将“项目”数组声明为可观察数组,并将其绑定到选项卡视图,然后,当对可观察数组的项目进行更新时,它将自动更新您的UI