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

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

问题描述

我已经看了很多ExtJS 4 MVC的例子,他们几乎都显示出同样的事情:应用程序创建一个视口,在视图中加载,并定义了一个'controllers',其中init是控制器:

  Ext.application({
name:'AM',

controllers:[
'用户
],

启动:function(){
Ext.create('Ext.container.Viewport',{
layout:'适合',
项目:[
{
xtype:'userlist'
}
]
});
}
});

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



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



这是正确的,你该怎么做? p>

我想澄清一点,在我的情况下,我需要两个SAME控制器/视图组合的独立实例。例如,我可能会看到一个选项卡面板和两个选项卡。然后我想在每个选项卡中放置Users控制器和user.List视图的两个独立实例。

解决方案


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


在extjs中,所有控制器在应用程序加载时获得实例化。您可以使用应用程序类中的启动方法启动视图。并让控制器听取该视图的事件。在控制器中,您可以随时使用应用程序访问其他控制器对象:

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

在上面的代码中,我调用一个方法 displayListPanel 在ControllerName1控制器中可用。该方法保存代码以在屏幕上显示视图(网格面板)。类似地,我可以使用创建视图的方法,如新的数据输入表单。这是另一个例子:

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

在我的方法中:

  newDataForm:function(){

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


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?

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

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);

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

and In my method:

newDataForm : function() {

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

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

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