1

我在主视图中声明包含。那么如何在控制器中访问。这里我有democontainerdemopanel。那么如何访问它。

    Ext.define('MyApp.view.Main', {
      extend: 'Ext.Panel',
      alias: 'widget.mainpage',


      config: {
        width: 710,
        margin: '10px auto 0',
        itemId: 'democontainer',
        layout: {
          type: 'hbox'
        },
        items: [
        {
          xtype:'container',
          cls:'wholeMenuWrap',
          margin: '65px 0 0 0',
          width: 175,

          items:[ 
....and
 {
    xtype: 'homepage',
    cls:'homepage-wrap',
    itemId: 'demopanel',
    layout: {
      type: 'fit'
    }
  },
  {
    xtype:'container',
    layout: 'vbox',
    margin: '65px 0 0 0',

    width: 185,
    items:[
    {
      xtype: 'titlebar',          
      cls:'roundedToolbar', 

我想像这样访问控制器,但我无法访问它。

    config: {
        main:this,
        profile: Ext.os.deviceType.toLowerCase(),

       refs:{
       myContainer: 'mainpage',
       },
        control: {
          'mainpage': {
            activate: 'onActivate',
            itemtap: 'onItemTap',
            },
'mainpage textfield[itemId=searchBox]' : {
//clear the input text box
clearicontap : 'onClearSearch',
//on every key stroke
keyup: 'onSearchKeyUp'
},

...........

   onSearchKeyUp: function(searchField) {
   var container = this.up('#democontainer');
          var panel = container.down('#demopanel');
          panel.removeInnerAt(0);
          var submitWordBySearch = { xtype: 'searchplusfav' }; 
          panel.insert(0, submitWordBySearch);

我收到此错误:

Uncaught TypeError: Object [object global] has no method 'up' 

任何人请帮帮我。

我添加了新代码:

    refs:{

         myContainer: 'mainpage',
         demoContainer2: '#democontainer', //same as demoContainer1
         demoContainer3:'#demopanel'
       },

...-------------
  onSearchKeyUp: function(searchField) {
 var container = this.getDemoContainer2();
           var panel = container.getDemoContainer3();
          panel.removeInnerAt(0);
          var submitWordBySearch = { xtype: 'searchplusfav' }; 
          panel.insert(0, submitWordBySearch);

得到错误:

Uncaught TypeError: Object [object global] has no method 'demoContainer2' 

工作代码:

  onKeySubmitTap: function(dataview, index, target, record, e, options) 
  {
    var container = dataview.up('#democontainer');
    var panel = container.down('#demopanel');
    panel.removeInnerAt(0);
    var submitWordBySearch = { xtype: 'categorywordsdisplay' }; 
    panel.insert(0, submitWordBySearch);
  }
4

2 回答 2

2

我为自己的问题添加了这个,这是确切的工作:

 var container = Ext.Viewport.up('#democontainer');
  var panel = Ext.Viewport.down('#demopanel');
  panel.removeInnerAt(0);
  var submitWordBySearch = { xtype: 'submitnewdefinitionholder' }; 
  panel.insert(0, submitWordBySearch);
于 2013-08-19T04:49:51.270 回答
0

在控制器中使用this.up()不会真正做任何事情。要获得对 democontainer 的引用,您首先应该意识到itemIdconfig类中声明 an 是无用的;这真的应该在声明类实例时完成。您基本上已经有了参考,#democontainer因为这两个与您当前的类配置等效:

refs: {
    demoContainer1: 'mainpage',
    demoContainer2: '#democontainer' //same as demoContainer1
}

因此,使用ref您已经拥有的,稍后在控制器中获取该引用,您需要使用的是this.getMyContainer()

refs: {
    myContainer: 'mainpage',
},
....
onSearchKeyUp: function(field) {
    var container = this.getMyContainer();
    ....
}
于 2013-08-15T11:27:23.700 回答