PDA

View Full Version : How to pass object form controller to view constructor ?



sekaijin
7 Aug 2013, 4:59 AM
Hi I'm using MVC architecture and I'm try to add a List Filter to the grid of "Sample MVC app" from tutorial

I've defined a store UsersList anda Model.
I've added store and model to the Uers controller

I'm try to add this store to the view
but in crontroller, I can get the store but not the view
and in view, I can't get the controller

now I'm using this solution. but I think that is not a good solution. (in view)

initComponent: function() {
var optionsStore = AM.store.UsersList.create(); // :sad: is private methode

this.columns = [
{header: 'Name', filter: {
type: 'list',
// How to get the store define by controller store: ??.getController().getStore('UsersList)
store: optionsStore
} , dataIndex: 'name', flex: 1},
{header: 'Email', filterable: true, dataIndex: 'email', flex: 1}
];

this.callParent(arguments);
}
I'm think that the solution is to call the controller to get the UserList store.

How to pass the instance of UserList store from controller to view constructor ?

thank
A+JYT

Lukappa
7 Aug 2013, 7:34 AM
I think there isn't only 1 way.
Maybe you could try something like that:

Controller:


createViewMethod: function() {
yourMainPanel.add(Ext.create("Your.path.of.View", {
mySuperStore: Ext.create("Your.path.of.Store") // or you get the ref to store like this.getMySuperStore()....

}));

}


View


initComponent: function() {
this.columns = [
{header: 'Name', filter: {
type: 'list',
store: this.mySuperStore
} , dataIndex: 'name', flex: 1},
{header: 'Email', filterable: true, dataIndex: 'email', flex: 1}
];


this.callParent(arguments);
}

sekaijin
15 Aug 2013, 11:34 PM
Thank for this suggest

i've include this in MVC tutorial
editUser: function(grid, record) {
var view = //Ext.widget('useredit');
Ext.create("AM.view.user.Edit", {store: this.getUserListStore()};

view.down('form').loadRecord(record);
}

but when the main view include include (in tab) the view controled by other controler

I've used this.getApplication().getUserControler().getMyStore();

A+JYT