我的标签组中有三个标签。一个选项卡用于更改语言。如果用户更改语言,我应该需要更改所有选项卡的选定语言。我的标签组代码如下,
<Alloy>
<TabGroup id="myTabGrp"> //Tabgroup Added
<Tab id="one">
<Window class="container">
<Label>This is the Home View</Label>
</Window>
</Tab>
<Tab id="two">
<Window class="container" id="winTwo">
<Label>This is the second View</Label>
</Window>
</Tab>
<Tab id="three">
<Window class="container">
<Button onClick="saveLang">Proceed</Button>
</Window>
</Tab>
</TabGroup>
</Alloy>
所有的ui文本都从数据库丢失。因此,我该如何重新加载tab3中“继续”按钮的时钟选项卡。
我尝试了以下代码,
function saveLang() {
$.myTabGrp.setActiveTab($.two);
}
$.winTwo.addEventListener('focus',function(e) {
// How can I reload the tab2 here....
alert('focus');
});
如果我尝试以下代码,则一切正常,但是,加载它花费的时间太长,它将在3秒钟内构建,然后加载所需的输出。我需要避免较长的加载时间。
var homeWindow = Alloy.createController('index').getView();
homeWindow.open({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
关于如何以更少的加载时间重新加载选项卡的任何建议。
您的问题的某些部分回答了here ( how to redirect from one page to tab in another page in titanium? )。
当您切换到选项卡二或winTwo或打开tabGroup时,将调用某些函数来更新窗口UI。也许您会在index.js
中看到以下内容:
$.myTabGrp.open();
updateWin1();
updateWin2();
updateWin3();
function updateWin1() {
var value = "Win1"; //fetched from local db
$.win1Label.text = value;
}
function updateWin2() {
var value = "Win2"; //fetched from local db
$.win2Label.text = value;
}
function updateWin3() {
var value = "Win3"; //fetched from local db
$.win3Label.text = value;
}
现在在您的[[winTwo的焦点EventListener中,调用updateWin2
方法(如下所示:):
$.winTwo.addEventListener('focus',function(e) {
//Reloaded
updateWin2();
});
注意:根据需要,可以在方法
P.S:如果您使用的是合金模型和收藏概念,则应尝试Alloy Data Binding。updateWin2()
中进行任意数量的UI操作。