我的标签组中有三个标签。一个选项卡用于更改语言。如果用户更改了语言,我应该更改所有选项卡的选定语言。我的标签组代码如下,
<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});
有关如何以较少的加载时间重新加载标签的任何建议。
答案 0 :(得分:1)
您的问题的某些部分已经回答here ( how to redirect from one page to tab in another page in titanium? )。
当您切换到标签2或 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();
});
注意:根据您的要求,您可以在方法updateWin2()
中进行任意复杂的UI操作。
P.S:如果您使用的是合金模型和集合概念,则应尝试Alloy Data Binding。