2012-04-03 76 views
0

我正在使用Sencha Touch 2,我需要創建一個TitleBar,它被吸入一組屏幕。 TitleBar元素是下拉列表。下拉列表中的項目必須是動態的,並且必須從數據文件中加載。Sencha Touch 2 - 使用商店填充標題欄

我已經設法加載數據,但我無法將數據傳回給TitleBar。換句話說,我需要以某種方式創建對標題欄的引用。

代碼:

Ext.define('CustomerToolbar', { 
extend: 'Ext.TitleBar', 


xtype: 'customer-toolbar', 


initialize: function() { 
    this.callParent(arguments); 

    this.loadItems(); 




    console.info("end of init");  
}, 


config: { 
    layout: 'hbox', 


    defaults: { 


    } 
}, 


loadItems: function (titleBar) { 
    var itemList = []; 
    var itemOptionList = []; 


    Ext.getStore('OrganizationStore').load(function(organizationList) { 


     console.info("getOptionList inside the store load function"); 


     Ext.each(organizationList, function(organization) { 


      console.info("organizations: " + organization.get("name") + "," + organization.get("id")); 
      itemOptionList.push({text: organization.get("name"), value: organization.get("id")}); 


     }); 


     console.info("itemList - about to populate"); 
     itemList.push(
      { 
       xtype: 'selectfield', 
       name: 'customerOptions', 
       id :'organizationId', 
       options: itemOptionList, 
       action :'selectOrganizationAction' 
      } 
     ); 
     console.info("itemList - populated"); 
     console.info("itemList within the store block: " + itemList); 


     console.info("this: " + this); 


     //THIS IS WHERE I AM HAVING THE PROBLEM. 
     //The variable this points to the store and not to the TitleBar 
     //this.setItems(itemList); 


    }); 


    console.info("itemList outside the store block: " + itemList); 
} 

});

回答

0

您可以將監聽器添加到您的selectfield並做

listeners:{ 
      change:function(){ 
       title = Ext.getCmp('organizationId').getValue(); 
       Ext.getCmp('TitlBarID').setTitle(title); 
      } 
     } 

我知道Ext.getCmp是不時髦,但它的工作原理

+0

我在控制器使用Ext.getCmp和它的作品!非常感謝 – alexgrimaldi 2012-04-05 11:55:44