2

我在 extjs4 MVC 中工作。在这里我卡在我想显示页面的地方,假设有链接。点击第一个视图的链接后,我将重定向到另一个视图。我的要求当我要单击第二个视图按钮时,我想获取第一个视图或别名的参考或别名。

这是查看代码:-
1)第一个视图:--

Ext.define('App.view.left.WordOfTheDay',    {
    extend:'Ext.panel.Panel',
    alias:'widget.WordOfTheDay',
    localized:true,

    xMore:"more",
    xTitle:"Word Of The Day",
    initComponent: function () {
        Ext.apply(this, {
            title:this.xTitle,

            items:[
                   {
                     xtype:'panel',
                     html:'<br>sdf<br>sdfsdf<br>sdsddf<br><a href="#" id="wordOfDay">'+this.xMore+'</a>',
                   }]
        });
        this.callParent();
    }
});// End of login class

及其设计 在此处输入图像描述 2)第二视图设计:-

在此处输入图像描述

单击第一个视图后,它显示第二个视图。当我单击第二个视图键登录按钮时,我想获得第一个视图的参考或第一个视图的别名。我正在处理它,但我没有得到解决方案。请给我的一些指导方针。

4

1 回答 1

0

一种可能的解决方案是为每个视图分配一个唯一的 id,然后使用Ext.ComponentManager.get('view-id')来获取引用。例如:

Ext.define('MyPanel1', {
  extend: 'Ext.Component',
  xtype: 'mypanel1',

  id: 'my-panel-1',
  html: 'Panel 1 <a href="#">Go</a>',

  initComponent: function() {
    this.on('afterrender', function() {
      this.getEl().down('a').on('click', function() {
        Ext.ComponentManager.get('my-panel-2').show(); // go to second view
        this.hide();
      }, this);
    }, this);
  }
});

Ext.define('MyPanel2', {
  extend: 'Ext.Component',
  xtype: 'mypanel2',

  id: 'my-panel-2',
  html: 'Panel 2 <a href="#">Back</a>',

  initComponent: function() {
    this.on('afterrender', function() {
      this.getEl().down('a').on('click', function() {
        Ext.ComponentManager.get('my-panel-1').show(); // back to first view
        this.hide();
      }, this);
    }, this);
  }
});

Ext.onReady(function() {
  Ext.create('Ext.container.Container', {
    items: [
      {
        xtype: 'mypanel1',
      },
      {
        xtype: 'mypanel2',
        hidden: true,
      }
    ],
    renderTo: Ext.getBody()
  });
});

在 Plunker 上试试

于 2013-05-30T07:47:43.330 回答