2013-12-18 98 views
0

我有一個具有共同視圖的dojox.mobile網站。我想重複使用多個「按鈕」視圖,並調用一個函數,根據按下哪個按鈕來更改視圖標題的標籤。但是,當我更改innerHTML時,後退按鈕消失。當我使用setattr函數時,標籤不會更改。處理這個問題的正確方法是什麼?更改Dojox.Mobile.Heading的標籤屬性

< /鏈接> - > 演示這個問題

<div id="MainMenu" data-dojo-type="dojox.mobile.View" data-dojo-props="selected: true" style="width: 100%; height: 100%;"> 
     <h1 data-dojo-type="dojox.mobile.Heading">View A</h1> 

     <h2 dojoType="dojox.mobile.RoundRectCategory">Select a View</h2> 
     <ul data-dojo-type="dojox.mobile.RoundRectList"> 
      <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="rightText:'Go!', moveTo: 'generic_view_x', callback:SetupViewA"> 
       View A 
      </li> 
      <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="rightText:'Go!', moveTo: 'generic_view_x', callback:SetupViewB"> 
       View B 
      </li> 
     </ul> 
    </div> 

    <div id="generic_view_x" data-dojo-type="dojox.mobile.View" style="width: 100%; height: 100%;"> 
     <h1 id="view_x_header" data-dojo-type="dojox.mobile.Heading" data-dojo-props="back:'Main', moveTo:'MainMenu',label:'test'"></h1> 

      <div id="map_canvas" style="width: 100%; height: 100%;"> 
       Some Other Stuff Here 
      </div> 


    </div> 



    <!-- configure and load dojo --> 
    <script src="./dojo/dojo.js" data-dojo-config="async:1, mblAlwaysHideAddressBar:true"></script> 

    <script> 

     require(["dojo"], function(dojo){ 

     SetupViewA = function(){ 
      // Doing it This way removes the back button 
      // document.getElementById('view_x_header').innerHTML = 'View A'; 
      // This doesn't change anything 
      dojo.setAttr("view_x_header", 'label','View A') 

     } 
     SetupViewB = function(){ 

       document.getElementById('view_x_header').innerHTML = 'View B'; 

     } 


       }) 

     require(["dojox/mobile/parser", "dojox/mobile", "dojox/mobile/deviceTheme", "dojox/mobile/compat", "dojo/domReady!"], 
       function(parser) { 
       parser.parse(); 
       }); 


    </script> 

</body> 

回答

1

隨着小部件,如頭部,最好使用其get/set方法來改變小部件的屬性。

你應該使用:

dijit.registry.byId("view_x_header").set("label", "View B"); 

小提琴:: http://jsfiddle.net/theinnkeeper/Wgx8u/

+0

真棒。謝謝,它修復了它。我以前嘗試dijit.byId沒有成功。我想我是指以前的dojo API? – user2855135

+0

是dijit.byId是1.7之前。他們將窗口小部件查找移動到它自己的名爲registry的包中 – tik27