PDA

View Full Version : PR4 approach to creating and referencing views?



bweiler
30 Jan 2012, 10:58 AM
I have been using the following get[ViewName]View() approach to get references to view constructors and I understand this will be changing going forward. In fact, if the views array is moved to the application definition, this old approach no longer works.

Old approach:


Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',


views: [
'MyList' // May belong in the app definition
],

var list = this.getMyListView().create();
...



Please explain the proper way to create and reference views going forward. I tried the following approach and it did not work.


Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',


views: [
'MyList' // Does the views array belong in the app definition?
],

refs: {
// It made sense to me to autoCreate the main
main: {
selector: 'mainview',
xtype: 'mainview',
autoCreate: true
},
// Do I have to autoCreate all views?
myList: 'mylistview', // Using xtype as selector
}

var main = this.getMain() // Works fine
...

// Create the first instance
var list = this.getMyList().create(); // Undefined, but not sure why
...
// Get subsequent references?
var list = this.getMyList(); // Didn't get this far
...

mitchellsimoens
30 Jan 2012, 12:10 PM
I use xtypes most of the time and use the requires within each view. I never subscribed to using the views array.

bweiler
30 Jan 2012, 12:50 PM
I use xtypes most of the time and use the requires within each view. I never subscribed to using the views array.

Will you please explain your comment a bit further. I am still not following. Here's the example in the updated Intro to Applications documentation:


Ext.application({
name: 'MyApp',
models: ['User', 'Product', 'Order'],
views: ['OrderList', 'OrderDetail', 'Main'],
controllers: ['Orders'],


launch: function() {
Ext.create('MyApp.view.Main');
}
});

The text says that this causes the classes listed in the arrays to be automatically loaded. I would think this means that I can reference them using the refs definition in the controller, but this does not seam to be the case. Providing some examples to clarify my confusion in my original post would be greatly appreciated.

Thanks

linuxyf
1 Feb 2012, 12:19 AM
i want to know same problem.

how to hide current view and show create and show another view as pr3?

linuxyf
1 Feb 2012, 1:22 AM
Will you please explain your comment a bit further. I am still not following. Here's the example in the updated Intro to Applications documentation:


Ext.application({
name: 'MyApp',
models: ['User', 'Product', 'Order'],
views: ['OrderList', 'OrderDetail', 'Main'],
controllers: ['Orders'],


launch: function() {
Ext.create('MyApp.view.Main');
}
});

The text says that this causes the classes listed in the arrays to be automatically loaded. I would think this means that I can reference them using the refs definition in the controller, but this does not seam to be the case. Providing some examples to clarify my confusion in my original post would be greatly appreciated.

Thanks

how to get 'OrderList', 'Main' view instance in controller.

i can get Main view instance by this.getMain(), but get undefined by this.getOrderList

edspencer
1 Feb 2012, 3:52 PM
The best way to do this in Touch 2.0 is to simply reference the name of the view (e.g. MyApp.view.OrderList). The getter function wasn't adding a great deal of value and causes additional processing to be performed at startup, slowing the application down. It may make a return but for the time being just create views like you would for any other class:



Ext.create('MyApp.view.OrderList');

linuxyf
1 Feb 2012, 5:24 PM
The best way to do this in Touch 2.0 is to simply reference the name of the view (e.g. MyApp.view.OrderList). The getter function wasn't adding a great deal of value and causes additional processing to be performed at startup, slowing the application down. It may make a return but for the time being just create views like you would for any other class:



Ext.create('MyApp.view.OrderList');


i know the create view instance as you said.

Ext.create('MyApp.view.OrderList');

but how to get the created view instance in controller.