2011-11-03 75 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部分。根據您的建議,我做了更改。但沒有運氣。驗證一次我錯誤的地方。 –