ExtJS 4 如何从另一个控制器/视图创建和显示新的控制器/视图? [英] ExtJS 4 how to create and display a new controller/view from another controller/view?

查看:30
本文介绍了ExtJS 4 如何从另一个控制器/视图创建和显示新的控制器/视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了许多 ExtJS 4 MVC 的示例,它们几乎都显示了相同的内容:应用程序创建了一个视口,加载到一个视图中,并定义了一个控制器",即 init 是控制器:

I have looked over lots of examples of ExtJS 4 MVC, and they all pretty much show the same thing: The application creates a viewport, loads in a view, and has a 'controllers' defined, which init's the controller:

Ext.application({
    name: 'AM',

    controllers: [
        'Users'
    ],

    launch: function() {
        Ext.create('Ext.container.Viewport', {
            layout: 'fit',
            items: [
                {
                    xtype: 'userlist'
                }
            ]
        });
    }
});

那太好了,但现在让我们在我的应用程序中说我想要一个包含在我的视图中的按钮来打开一个全新的控制器/视图,你怎么做?

Thats great, but now let's say in my application I want a button contained within my view to open a whole new controller/view, how do you do that?

我认为我正在寻找的是一种表达方式,例如:- 创建控制器(运行它的初始化代码)- 在控制器初始化代码中,创建视图并显示

I think what I am looking for is a way to say something like: - Create Controller (run it's init code) - in the controller init code, create the view and display it

这是正确的,你是如何做到的?

Is that correct, and how do you do this?

我想澄清一下,在我的情况下,我需要 SAME 控制器/视图组合的两个单独实例.例如,我可能有一个带有选项卡面板和两个选项卡的视图.然后我想在每个选项卡中放置两个单独的用户"控制器实例和user.List"视图.

I want to clarify that in my case I would need TWO individual instances of the SAME controller/view combination. For example, I might have a view with a tab panel and two tabs. I then want to put TWO separate instances of a 'Users' controller and 'user.List' view inside each tab.

推荐答案

我认为我正在寻找的是一种表达方式: - 创建控制器(运行它的初始化代码) - 在控制器初始化代码中,创建视图并显示它

I think what I am looking for is a way to say something like: - Create Controller (run it's init code) - in the controller init code, create the view and display it

在 extjs 中,所有控制器在应用程序加载时都会被实例化.您可以使用 Application 类中的启动方法来启动视图.并让控制器监听该视图的事件.在控制器中,您始终可以使用 application 对象访问另一个控制器:

In extjs, all controllers get instantiated when the application is loaded. You can use the launch method in the Application class to start off a view. And Have a controller listen to events of that view. In a controller, you can always access the other controller using the application object:

 this.application.getController('ControllerName1').displayListPanel(options);

在上面的代码中,我调用了 ControllerName1 控制器中可用的方法 displayListPanel.此方法保存在屏幕上显示视图(网格面板)的代码.同样,我可以拥有创建视图的方法,例如用于数据输入的新表单.这是另一个例子:

In the above code, I am calling a method displayListPanel that is available in ControllerName1 controller. This method holds the code to display a view (a grid panel) onto the screen. Similarly, I can have methods that create views like a new form for data entry. Here is another example:

this.application.getController('ControllerName1').newDateForm();

在我的方法中:

newDataForm : function() {

        var view = Ext.widget('form',{title: 'New Data'});
        view.show();
    },

这篇关于ExtJS 4 如何从另一个控制器/视图创建和显示新的控制器/视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆