Related to this thread in the Ext 5: Bugs forum: http://www.sencha.com/forum/showthre...ewModel-Stores
DESCRIPTION
Listeners do not work when added via the "View Controller Event Bindings" property to proxies and readers created within View Models. If you attempt to add a listener to a proxy or reader in this way then it will always fail declaring that the method could not be found within the Ext JS proxy or reader class.
In my case, I have a proxy named ResourceProxy and I would like the "exception" event to execute the "onResourceProxyException" method in the associated controller when fired.
FIDDLE
(3.1.0.1934) View Model Proxies and Readers - View Controller Event Bindings Broken
STAND-ALONE TEST CASE
Fiddle: http://ift.tt/12jYq1j
ENVIRONMENT INFORMATION
- Windows 7, 64-bit
- Architect:
version: | 3.1.0.1934 |
channel: | 3.1-stable |
platform: | 1.4.1.960 |
cmd: | 5.0.2.270 |
framework: | Ext JS 5.0.x (specifically, 5.0.1.1255) |
DESCRIPTION
Listeners do not work when added via the "View Controller Event Bindings" property to proxies and readers created within View Models. If you attempt to add a listener to a proxy or reader in this way then it will always fail declaring that the method could not be found within the Ext JS proxy or reader class.
It sounds like this feature is not supported yet in Ext JS, but they've opened an improvement request to possibly include this functionality in the future. See this thread in the Ext 5: Bugs forum: http://www.sencha.com/forum/showthre...ewModel-Stores
WORKAROUND
The best workaround I've seen in the meantime is this:
- Wrap the proxy or reader using the "Process Config" property.
- Bind a function within the ViewModel to maintain the ViewModel as the effective "this" property (could also just use a wrapper function).
- Attach a listener that triggers this function to the Proxy or Reader.
In my case, I have a proxy named ResourceProxy and I would like the "exception" event to execute the "onResourceProxyException" method in the associated controller when fired.
Code:
Ext.define("MyViewModel", {
...,
initConfig: function (instanceConfig) {
var me = this,
config = {
...
}
}
},
processResourceProxy: function(config) {
config.listeners = {
exception: this.onResourceProxyException.bind(this)
};
return config;
},
onResourceProxyException: function() {
var controller = this.getView().getController();
controller.onResourceProxyException.apply(controller, arguments);
}
}
FIDDLE
(3.1.0.1934) View Model Proxies and Readers - View Controller Event Bindings Broken
Aucun commentaire:
Enregistrer un commentaire