2014-04-16 120 views
0

我需要更改來自http://example.com/new.json的來自json的sencha touch 2中的工具欄標題。也許我應該使用AJAX調用來獲取json然後解析它......但是如何將值插入到title:''有沒有可能?sencha touch 2 json的工具欄標題

Main.js

Ext.define('Sencha.view.Main', { 
extend: 'Ext.Container', 
xtype: 'main', 
requires: [ 
    'Ext.Toolbar', 
    'Ext.Button', 
    'Ext.Img', 
    'Ext.Label', 
    'Ext.form.FieldSet' 
], 

config: { 
    layout: 'hbox', 
    items: [ 
     { 
      xtype: 'toolbar', 
      docked: 'top', 
      itemId: 'navBar', 
      title: 'app', // need to change 'app' from json dynamically 
      items: [ ..... ] 
     } 
    ] 
    } 
}); 

JSON例如

{ 
    data: { 
    add: { 
     application_config: { 
     datasources: [ 
      { 
      data: { 
       application_title: "test2" // 'test2' should be passed as value to title 
      } 
      } 
     ] 
     } 
    } 
    } 
} 

回答

0

所以你要找的Toolbar setTitle()

也許你在問如何訪問嵌套的工具欄來設置它的標題。

var newTitle = ''; // parse your JSON response here 

var mainView = Ext.Viewport.down('main'); // 'main' is the xtype of your view 
var toolbar = main.down('#navBar'); // '#navBar' is the component query to grab the component with an itemId of "navBar" 
toolbar.setTitle(newTitle); 

您可以隨意清理上面的代碼,但我特意詳細地解釋了完成此步驟的步驟。

+0

謝謝你。但是如果我在sencha架構中有json reader並且以這種方式解析json會怎麼樣:'rootProperty:'data.add.application_config.datasources [0] .data'' 和模板'

{application_title}
' ...如何使* * setTitle()**然後? – test1n

+0

完全相同的方式。只需在商店的加載事件處理程序中執行此操作:http://docs.sencha.com/touch/2.3.1/#!/api/Ext.data.Store-event-load – arthurakay