Extjs 4 MVC从控制器加载视图 [英] Extjs 4 MVC loading a view from controller

查看:106
本文介绍了Extjs 4 MVC从控制器加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定,所以我有一个控制器,我想加载一个视图的方法。

Ok so I have a controller with a method in which I want to load a view.


  1. 如何从控制器加载视图?

  2. 如何传递一些参数控制器在加载它时的视图?

任何帮助都非常感激。

推荐答案

要加载视图,可以使用 Ext.widget()。使用 Ext.define()在视图文件中创建一个视图。我建议使用别名属性来定义视图的内联xtype。

To load a view, you can use Ext.widget(). Use Ext.define() to create a view in your view file. I would recommend using the alias property to define an inline xtype for the view.

当您需要加载视图,您使用 Ext.widget()创建视图,并指定xtype(视图的别名)。这里有一个例子:

When you need to load the view, you create an view using Ext.widget() and specify the xtype (alias for your view). Here is an example:

 // define a window
 Ext.define('MyApp.view.user.Add',
    extend: 'Ext.window.Window',
    alias : 'widget.adduser',
    .
    . // Add other properties, custom properties, methods, event handlers etc..
 });

现在,当您要在用户控制器中创建一个实例时,您可以执行以下操作:

Now, when you want to create an instance in your user controller, you do:

// create an instance
 var view = Ext.widget('adduser'); // refer the below note!

注意:请注意,没有小部件。它会自动添加到您传递的小部件名称。

Note: note that there is no 'widget.'! it automatically gets added to the widget name you pass.

现在,接受传递参数。像Ext.create方法一样,您应该可以传递任何参数:

Now, taking about passing parameters. Like Ext.create method, you should be able to pass any parameters as:

 // create an instance with params
 var view = Ext.widget('adduser', {title: 'New User title'});

关于参考:参考可帮助您获取对页面浏览量的引用。他们没有帮助创建实例或加载视图。如果您的视图呈现,您可以使用引用系统来掌握该实例并操纵该视图。您需要使用组件查询来获取你的看法

Regarding ref: refs help you in getting references to Views on your page. They do not help in creating an instance or load a view. If you have your view rendered, you can make use of the ref system to get hold of that instance and manipulate the view. You need to make use of the ComponentQuery to get reference of your view.

这篇关于Extjs 4 MVC从控制器加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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