Load a script file in sencha, supports both asynchronous and synchronous approaches

时间:2022-01-10 03:09:05
//http://www.sencha.com/forum/showthread.php?188318-Ext.Loader.loadScriptFile-wrong-URL
Ext.Loader.loadScriptFile("/a.js", function() {
console.log('hello loadScriptFile callback'); }, undefined, true
);

//you can load script from local

//and also, you can load script from remote server

//for example,you can load a jquery lib from jquery CDN

Ext.Loader.loadScriptFile("http://code.jquery.com/jquery-2.0.3.js", function() {
console.log('hello loadScriptFile callback'); }, undefined, true
);
//you now can use jquery functions
console.log($('body')[0].innerHTML)
//above will error,you can't use $ at this place this moment, because the Loader loading files async,your code is not loaded just now
// you can try
//http://www.sencha.com/forum/showthread.php?188318-Ext.Loader.loadScriptFile-wrong-URL
Ext.Loader.loadScriptFile("http://code.jquery.com/jquery-2.0.3.js", function() {
console.log('hello loadScriptFile callback');
//once your script load successfully, you can use your functions from the new imported lib
console.log($('body')[0].innerHTML);
}, undefined, true
);