2011-11-22 156 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

相关问题