2011-11-03 74 views
0

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

我已经使用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'); 

回答

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() 
      } 
     } 
    }); 
+0

beforeactivate侦听器无法正常工作..它没有影响 –

+0

@Swar ..非常感谢.. beforeactivate工作时,我用内部Ext.apply .. –

0

您应该倾听beforecardswitch事件。例如

listeners:{ 
    beforecardswitch:function(newCard, oldCard, index, animated){ 
//do something... 
    } 
} 
+0

@ illija139 ..我必须使用这个侦听器的形式吗?我已经尝试过,但没有运气。 –

+0

您应该在用于切换视图的对象中使用此侦听器。例如,如果你使用'obj.setActiveItem(1);'然后在'obj'配置你应该,但应该听者。也试试听'cardswitch'事件。如果两者都不起作用,那么问题可能在于如何初始化屏幕组件。 – ilija139

+0

@ illija139 ..请检查edit1部分。根据您的建议,我做了更改。但没有运气。验证一次我错误的地方。 –