2013-04-01 59 views
0

如何在Sencha touch中調用getView( view_name)?我通常在extjs上做這個,但我不能在sencha touch中。我無法理解應用程序的概念。sencha touch getView()?

run_edit: function(data) { 
    $this = this; 
    this.mode = "update"; 
    this.data = data; 
    this.win = this.getView('Group_prop').create(); 

    var form = this.win.down('form'); 
    var util = this.getController('controller_Helper'); 

    form.getForm().loadRecord(data); 
    util.form_lock({ 
     form:form, 
     items:['GROUP_KODE'] 
    }); 
    util.form_require({ 
     form:form, 
     items:['GROUP_KODE','GROUP_NAMA'] 
    }); 

    this.win.show(); 
}, 
+0

也許你想用'Ext.getCmp( 'the_component_id')'。檢查Sencha文檔:http://docs.sencha.com/touch/2-1/#!/ api/Ext-method-getCmp – cclerville

+0

但該對象尚未製作。 ? –

+0

這種方法是你的控制器的一部分嗎?你是說你想通過控制器獲取視圖嗎? – cclerville

回答

0

好了,所以好像你正試圖獲取視圖:Group_prop 。確保此視圖在其配置中設置了id或最好是itemId。例如

Ext.define('MyApp.view.GroupProb', { 
    extend: 'Ext.Panel', 
    alias: 'widget.group_prob', 
    config: { 
     ... 
     itemId: 'groupProb', 
     ... 
    }, 
    .... 
}); 

現在在你的控制器中,你需要爲這個視圖創建一個引用來正確訪問它。因此,您的控制器將是這個樣子:

Ext.define('MyApp.controller.MyController', { 
    extend: 'Ext.app.Controller', 
    config: { 
     refs : { 
      groupProb : { 
       autoCreate: true, 
       selector: '#groupProb', 
       xtype: 'group_prob' 
      } 
     }, 
     control: { 
      ... 
     }, 
     ... 
    }, 
    run_edit: function(data) { 
     $this = this; 
     this.mode = "update"; 
     this.data = data; 
     this.win = this.getView('Group_prop').create(); 

     var form = this.win.down('form'); 
     var util = this.getController('controller_Helper'); 

     form.getForm().loadRecord(data); 
     util.form_lock({ 
      form:form, 
      items:['GROUP_KODE'] 
     }); 

     this.win.show(); 
    }, 
    ... 
}); 
run_edit功能

現在,它好像你與windowsthis.win變量(糾正我,如果我錯了)的工作。在Sencha Touch中,您使用​​。同樣在該功能結束時,您可以撥打this.win上的show功能,這表示您希望在顯示this.win時執行run_edit。話雖這麼說,你可能希望你的run_edit功能看起來是這樣的:

run_edit: function() { 
    var me = this, 
     mode = 'update', 
     data = data, 
     groupProbPanel = me.getGroupProb(); 

    // This assumes that your form component has an itemId. 
    // You need one inorder use the down method. 
    var form = groupProbPanel.down('#form_itemId'); 

    // You may want to double check this. I don't think that is how you 
    // you get the controller. 
    var util = this.getController('controller_Helper'); 

    form.getForm().loadRecord(data); 
    util.form_lock({ 
     form:form, 
     items:['GROUP_KODE'] 
    }); 
} 

因爲我們希望在groupProbPanel顯示我們需要設置一個show event listener我們control配置這樣的事情發生。所以,你的控制器的config應該是這樣的:

..., 
config: { 
    refs : { 
     groupProb : { 
      autoCreate: true, 
      selector: '#groupProb', 
      xtype: 'group_prob' 
     } 
    }, 
    control: { 
     groupProb : { 
      show: 'run_edit' 
     }, 
     ... 
    }, 
    ... 
}, 
... 
+0

哇,你搖滾。 非常感謝你,我明白了。 我已經嘗試過。 N關於這個.win,對不起,我是一個新手在sencha touch :)。 非常感謝。 –

+0

我很高興這很有幫助。 – cclerville

1

我看你要創建一個視圖,它設置爲窗口,在煎茶觸摸,你可以做這樣的:

Ext.Viewport.add(Ext.create('MyApp.view.ViewName')); 

,而不是視口,你可以採取任何其他容器,並設置新創建的視圖將其

Ext.getCmp('myContainerId').add(Ext.create('MyApp.view.ViewName')); 

後來取這個觀點,你必須考慮到指定id配置,然後把它像這樣:

var view = Ext.getCmp('ViewId'); 
0

兩種方法有調用瀏覽

1.

 Ext.Viewport.setActiveItem({xtype:'TwowayMakePayment'}); // view xtype 

2.

 var getti=Ext.create('VUCFyn.view.AfterLogin'); //create object 4 d view 
    Ext.Viewport.add(getti);  // next add the object 
    Ext.Viewport.setActiveItem(getti);  // final Active that obj 
+0

我已經試過這個,但是我想從控制器中調用視圖(包含在我的控制器中的視圖)。我該怎麼辦? –

+0

告訴我清楚在哪個行動中你想打電話給觀衆 –