Is it possible to create component from remote json object in ExtJS
Now I use
Ext.create('Ext.Viewport',{...});
to c开发者_StackOverflow社区reate extjs components.
Is it possible to create component from remote json object in ExtJS like this:
Ext.create('Ext.Viewport','http://blabla/viewport.js');
then I can write the viewport config json object in viewport.js.
Nothing built into the framework. There is ComponentLoader with the component renderer but that is for rendering components within a container, not to set up a Component.
What you could do is first thing in your constructor method, fire off a sync AJAX request to get the config object and then apply it to the config argument:
...
constructor: function(config) {
var me = this;
Ext.Ajax.request({
url : 'something.php',
async : false,
params : {
componentId : 'something'
},
callback : function(opts, success, response) {
var json = response.responseJSON;
// or var json = Ext.decode(response.responseText, true);
Ext.applyIf(config, json); //or Ext.apply(config, json);
}
});
me.callParent(arguments);
},
....
Technically this should halt everything until the AJAX request comes back. You need error handling of course. You can use Ext.applyIf if you want the config Object to be primary and the json Object will apply if the key doesn't have a match in the config Object. Ext.apply if you want to plainly overwrite if there are matches.
精彩评论