2011-11-22 126 views
1

我有一個列表面板,我添加了onItemDisclosure應該切換到頁面(在標籤面板)。 setActiveItem不起作用,我得到的錯誤是:[undefined]不是一個函數。 代碼:setActiveItem不能從面板sencha

Toolbar.views.listPanel = Ext.extend(Ext.List,{ 
     id:'mylist', 
     store:ListStore, 
     itemTpl: '<div class="stores"><b>{name}</b><br/><p style="font-size:small">{address}{distance}Km</p></div>', 
     //grouped:true, 
     onItemDisclosure: function(){ 
       //Ext.Msg.alert("closure works!"); 
       //Toolbar.views.detailPanel.update(); 
       //alert(Toolbar.views.detailPanel); 
       Toolbar.views.Searchcard.setActiveItem(Toolbar.views.detailPanel,{type:'slide',direction:'left'}); 
     } 

    }); 

面板,切換到:

Toolbar.views.detailPanel = Ext.extend(Ext.Panel,{ 
id:'detailpanel', 
tpl:'Hello!' 
}); 

Ext.reg('searchcard', Toolbar.views.Searchcard); 
Ext.reg('listPanel', Toolbar.views.listPanel); 
Ext.reg('detailPanel', Toolbar.views.detailPanel); 

由於提前,

+1

太棒了。通常當我告訴人們他們不理我時。 :)這是最令人欣賞的和什麼使得SO偉大的一部分。 –

回答

1

問題是你要引用類Searchcard的不是實例。您必須使用組件查詢來引用它。

一般來說,如下這樣:

masterComponent.getComponent('your_component_itemID'); 

或者你可以使用panel.query(選擇)

http://docs.sencha.com/touch/1-1/#!/api/Ext.Panel-method-query

真的,而不是僅僅黑客通過它來看看這篇文章: http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap/

+0

嗨, 感謝您的回覆。 請給我更具體的例子嗎? 我不明白。 另外我鑽了你給我的鏈接,它和我的代碼完全不同,我不想改變我的整個代碼。 – Elad

+0

在你的onItemDisclosure函數中 你需要有一些代碼,如 Ext.view.Viewport .getComponent('panelAttachedToComponent')。getComponent(..)and drill down 或者你可以做類似 thisPanel.setActiveItem(Ext.ComponentQuery.query(theSelector)) 選擇器可以是xtype thisPanel是對你的引用父面板,而不是類類型,但是該類的實例。 我真的很推薦閱讀那篇文章,你只會給自己一個更大的麻煩,最終把代碼亂碼在一起。 – stan229

+0

謝謝, 我會和我會嘗試... – Elad

相關問題