【问题标题】:setActiveItem doesn't work from panel senchasetActiveItem 在面板 sencha 中不起作用
【发布时间】:2011-11-22 16:48:29
【问题描述】:

我在标签面板中有一个列表,我添加了onItemDisclosure,它应该切换到一个进入页面(在标签面板内)。 setActiveItem 不起作用,我得到的错误是:[undefined] is not a function。 代码:

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);  

提前致谢,

【问题讨论】:

  • 太棒了。通常当我告诉人们他们不理我时。 :) 这是最受赞赏的,也是如此伟大的一部分。

标签: sencha-touch


【解决方案1】:

问题是您引用的是类而不是 Searchcard 的实例。您必须使用组件查询来引用它。

一般是这样的:

masterComponent.getComponent('your_component_itemID');

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

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

真的,而不是仅仅通过看看这篇文章来破解它: http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap/

【讨论】:

  • 您好,感谢您的回复。你能给我更具体的例子吗?我不明白。另外我钻了你给我的链接,它和我的代码完全不同,我不想改变我的整个代码..
  • 在您的 onItemDisclosure 函数中您需要有一些代码,例如 Ext.view.Viewport.getComponent('panelAttachedToComponent').getComponent(..) 并向下钻取,或者您可以执行类似 thisPanel.setActiveItem 的操作(Ext.ComponentQuery.query(theSelector)) 选择器可以是 xtype thisPanel 是对父面板的引用,不是类类型,而是该类的实例。我真的建议您阅读那篇文章,最终将代码组合在一起只会让自己更加头疼。
猜你喜欢
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多