0

我有一个屏幕,其中 formBase 包含所有动态创建的 UI 控件。我正在使用卡片布局并在视图之间切换。现在碰巧每次卡片切换时我都必须执行formBase(我的意思是每次我的屏幕出现时)。

我已经使用了 beforeshow 监听器来实现这一点。但它不起作用。下面是我的代码。

var formBase = new Ext.form.FormPanel({
        scroll: 'vertical',
        ui: 'round',
        items: [fieldSet, {
            xtype : 'fieldset',
            items : [ item1, item2, item3]
            ]
        }],
         listeners: {
            beforerender: function(ele) {
               console.log(" Screen before render");
               initScreenComps()
            },

            beforeshow: function(ele) {
                console.log(" screen before show");

            }
        }
    });

编辑:1

我有一个 viewport.js 文件,其中有显示更改视口的方法。这是 Viewport.js 的以下代码。仍然没有效果。请建议。

MyApp.views.Viewport = Ext.extend(Ext.Panel, {
    fullscreen: true,
    layout: 'card',
    initComponent: function() {
        Ext.apply(this, {

            items: [
                { xtype: 'MyApp.views.view1', id: 'view1' },
                { xtype: 'MyApp.views.view2', id: 'view2' },
                { xtype: 'MyApp.views.view3', id: 'view3' },
                { xtype: 'MyApp.views.view4', id: 'view4' },
                { xtype: 'MyApp.views.view5', id: 'view5' }             
            ],
        listeners:{
           beforecardswitch:function(newCard, oldCard, index, animated){
                 //do something...
               console.log(" Card switched"  + " New " + newCard + " OLD : " + oldCard + " index + " index);
           }
        }
        }
        );
        MyApp.views.Viewport.superclass.initComponent.apply(this, arguments);
    },

    // used for changing view port of application
    reveal: function(target) {      
        this.setActiveItem(MyApp.views[target],{ type: 'slide', direction: 'right' }
        );
    }
});

现在我在按钮单击事件上从控制器调用 view2。

MyApp.views.viewport.reveal('view2');
4

2 回答 2

1

我认为,最好使用“beforeactivate”或“activate”事件监听器。只要卡片布局将此项目设置为活动项目,就会触发这些事件。所以,代码将是这样的:

var formBase = new Ext.form.FormPanel({
        scroll: 'vertical',
        ui: 'round',
        items: [fieldSet, {
            xtype : 'fieldset',
            items : [ item1, item2, item3]
            ]
        }],
         listeners: {
            beforeactivate: function(panel) {
               console.log(" Screen before render");
               initScreenComps()
            }
        }
    });
于 2011-11-03T13:21:53.683 回答
0

您应该改为监听beforecardswitch事件。例如

listeners:{
   beforecardswitch:function(newCard, oldCard, index, animated){
 //do something...
   }
}
于 2011-11-03T12:04:01.630 回答