我正在使用以下选项卡控件:
function tweetsAction()
{
var w = dojox.mobile.currentView;
if (w.id != "tweetsView") w.performTransition('tweetsView', 1, "slide", null);
}
function secondAction()
{
var w = dojox.mobile.currentView;
if (w.id != "secondView") w.performTransition('secondView', 1, "slide", null);
}
function thirdAction()
{
var w = dojox.mobile.currentView;
if (w.id != "thirdView") w.performTransition('thirdView', 1, "slide", null);
}
在 Worklight JavaScript 中初始化它们,例如:
function initCommonControls()
{
console.log("Android initCommonControls");
WL.TabBar.init();
WL.TabBar.addItem("tweetsView", tweetsAction, "Tweets", {image:"images/icons/help_bw.png", imageSelected:"images/icons/help.png"});
WL.TabBar.addItem("secondView", secondAction, "Second", {image:"images/icons/help_bw.png", imageSelected:"images/icons/help.png"});
WL.TabBar.addItem("thirdView", thirdAction, "Third", {image:"images/icons/help_bw.png", imageSelected:"images/icons/help.png"});
WL.TabBar.setSelectedItem("tweetsView");
}
标签在应用启动时显示正常:
但是,当我单击第二个或第三个选项卡时,这两个选项卡都会移动到第一个选项卡上:
我在 JS 控制台中看到了这个 JavaScript 错误:
未捕获的类型错误:无法读取未定义的属性“id”
这意味着`var w = dojox.mobile.currentView; 移出初始选项卡后无法获取当前视图。
这就是我的 HTML 的样子:
<!-- Tweets View -->
<div id="tweetsView" data-dojo-type="dojox.mobile.ScrollableView" data-dojo-props="selected: true">
<div class="spacing"></div>
<h1 id="head0" data-dojo-type="dojox.mobile.Heading"
data-dojo-props="label:'Tweet Search', fixed:'top'"></h1>
<button onclick="getTweets()">Get Tweets</button>
<input data-dojo-type="dojox.mobile.TextBox" id="sampleItem">
<ul data-dojo-type="dojox.mobile.EdgeToEdgeList" id="theTable"
class="tweetviewList">
</ul>
</div>
<!-- second View -->
<div id="secondView" data-dojo-type="dojox.mobile.ScrollableView" data-dojo-props="selected:false">
<div class="spacing"></div>
<h1 data-dojo-type="dojox.mobile.Heading"
data-dojo-props="label:'second view', fixed:'top'"></h1>
This is a second view
</div>
<!-- third View -->
<div id="thirdView" data-dojo-type="dojox.mobile.ScrollableView" data-dojo-props="selected:false">
<div class="spacing"></div>
<h1 data-dojo-type="dojox.mobile.Heading"
data-dojo-props="label:'third view', fixed:'top'"></h1>
This is a third view
</div>
关于为什么dojox.mobile.currentView
在切换标签后什么都不返回的任何想法?