Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4 MVC loading a view from controller

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

  1. How do I load a view from a controller?
  2. How do I pass some parameters from the controller to the view when I load it?

Any help is much appreciated.

like image 595
Rob P. Avatar asked May 04 '11 21:05

Rob P.


People also ask

What is viewcontroller in Ext JS 5+?

While Ext JS 5+ is backwards compatible with legacy application-level controllers, it introduces a new type of controller designed to handle these challenges: Ext.app.ViewController. ViewController does this in the following ways: Simplifies the connection to views using “listeners” and “reference” configs.

How do I load a view in an ext view?

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:

How do I setup the web environment in ExtJS 4?

Next copy all the folders and the files from your ExtJs 4 installation directory inside the WebContent > extjs folder. To setup the web environment first create the context.xml file inside the META-INF.

What's new in extext JS 4?

Ext JS 4 comes with a new application architecture that not only organizes your code but reduces the amount you have to write. It introduces the concept of controller into the design of the application. Controllers are the glue that binds an application together.


1 Answers

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.

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.

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.

like image 171
Abdel Raoof Olakara Avatar answered Nov 16 '22 00:11

Abdel Raoof Olakara