dojox.mobile.currentView is null after moving from one tab to another
-
12-12-2019 - |
Question
I'm using the following tab controls :
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);
}
Initialising them in Worklight JavaScript, such as :
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");
}
Tabs appear OK on app launch :
However, when I click on either the second or third tab, both of those move over the first one :
And I see this JavaScript error in the JS console :
Uncaught TypeError: Cannot read property 'id' of undefined
Which means that `var w = dojox.mobile.currentView; is not able to get the current view after moving off the initial tab.
This is what my HTML looks like :
<!-- 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>
Any ideas as to why the dojox.mobile.currentView
is returning nothing after switching a tab?
Solution
I would guess that it's related to this: http://bugs.dojotoolkit.org/ticket/15040. Sounds like they've removed dojox.mobile.currentView from the latest versions of Dojo Mobile. I'm currently doing some stuff with Worklight and I'm also getting 'undefined' for dojox.mobile.currentView.
There's a couple of recommendations on that page, but it seems everything now needs to be much more complex - yay :(