-
Sending parameter to js
Hi,
I have a varialble in Controller like,
Code:
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
onFieldButtonClick: function(button, e, options) {
var groupChecked = Ext.getCmp('groupgrid').getSelectionModel().getSelection();
var arrayValues = [];
Ext.each(groupChecked, function(rec, index) {
arrayValues.push(rec.get('colName'));
});
var MyGrid = Ext.ComponentQuery.query('MyGrid')[0];
MyGrid.getStore().reload({
params:{
singleton: true,
param1: [arrayValues]
}
});
...
I want to use this arrayValues in another js in another location, I am doing,
Code:
groupField: MyApp.controller.MyController.param1
But I am not getting the value there, how should I do to get the selected value?
-
When you create your application in the Ext.application's init function do this:
Code:
init: function () {
MyApp.app = this;
}
Then you'll have access to the application using MyApp.app. From there you can do:
Code:
groupField: MyApp.app.getController('MyController').param1; // provided param1 is a property of the controller itself
-
This isn't working, when I alert,
Code:
MyApp.app.getController('MyController').param1
in the new file, it says "undefined" :-/.
-
If you do console.log(MyApp.app.getController('MyController')) do you see the param1 property in the list? Do you see any other properties / methods belonging to MyController?
-
It just shows something like this,
Code:
Object { application={...}, id="MyController", hasListeners={...}, more...}
When I click for more info, there are lots of data, but there isn't anything related to param1 :-|.
Forget about parameters, I have this variable in controller,
Code:
var groupData = Ext.ComponentQuery.query('#groupid')[0].getValue();
I have to have this variable in another js, groupData like that,
Code:
groupField: groupData
How should I do this?
Thanks for the reply BTW :).
-
-
I would use a store, to save the data in it and load it from the other controller.
I guess it could be also a problem with the asynchron behavior of ExtJs. But try it with a store first ^^
-
Is it that difficult to pass a variable to another JS? I thought it will be as simple as passing a parameter to a PHP :-?.
-
PHP runs synchron, so the whole scripts runs one time and finished. ExtJs uses alot of events. For that it must run the whole time to listen to the events. Because of that the MVC structur differs from PHP alot.
You could also call a method in the other controller and pass the data to it.
-
Hi,
It worked like this,
Code:
Ext.define('MySharedData', {
singleton: true,
foo: 'bar',
meh: 42
});
Can then access using MySharedData.foo, for instance.
Found in,
http://www.sencha.com/forum/showthre...ble-in-Extjs-4
Didn't try it correctly initially, now works good, it doesn't do grouping like expected anyway :-|.