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

查看:27
本文介绍了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() 在您的视图文件中创建一个视图.我建议使用 alias 属性为视图定义内联 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'});

关于引用:引用可帮助您获取对页面上视图的引用.它们无助于创建实例或加载视图.如果您渲染了视图,则可以使用 ref 系统来获取该实例并操作视图.您需要使用 ComponentQuery 来获取参考你的看法.

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天全站免登陆