sencha touch getView()?

时间:2013-04-01 01:43:45

标签: sencha-touch

如何在Sencha touch中调用getView( view_name)`?我通常在extjs上做这个,但我不能在sencha touch。我无法理解应用程序的概念。

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

3 个答案:

答案 0 :(得分:1)

我看到你正在尝试创建一个视图并将其设置为窗口,在sencha touch中你可以这样做:

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

而不是Viewport,您可以使用任何其他容器并将新创建的视图设置为

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

稍后获取此视图,您必须在视图中指定id配置,然后按以下方式获取:

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

答案 1 :(得分: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

答案 2 :(得分:0)

好的,好像你正试图获得视图:Group_prop。确保此视图在其配置中设置了id或最好itemId。 e.g

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函数中,您似乎正在使用windows变量中的this.win(如果我错了,请更正我)。在Sencha Touch中,您可以使用Panels。同样在此功能的最后,您调用show上的this.win功能,这表示您希望在显示run_edit时执行this.win。话虽如此,您可能希望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时发生这种情况,因此我们需要在control配置中设置show event listener。所以你的控制器的config应该是这样的:

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