//load *.js file from server
functionloadScript(url, callback) {varscript=document.createElement("script")
script.type= "text/javascript";if(script.readyState) {//IE
script.onreadystatechange= function() {if(script.readyState== "loaded" ||script.readyState== "complete") {
script.onreadystatechange= null;
callback();
}
};
}else{//Others
script.οnlοad= function() {
callback();
};
}
script.src=url;
document.getElementsByTagName("head")[0].appendChild(script);
}//load js text from server
functionloadScriptSrc(js, callback) {varscript=document.createElement("script")
script.type= "text/javascript";//script.async = true;
if(script.readyState) {//IE
script.onreadystatechange= function() {if(script.readyState== "loaded" ||script.readyState== "complete") {
script.onreadystatechange= null;
callback();
}
};
}else{//Others
script.οnlοad= function() {
callback();
};
}
script.text=js;
console.log(script);
document.getElementsByTagName("head")[0].appendChild(script);//不能少
callback();
}//Ext JS 6
Ext.onReady(function() {//https://www.sencha.com/forum/showthread.php?268193-How-to-load-content-dynamically-for-tabpanel
varpmain=Ext.widget('panel', {
renderTo: document.body,
height:800,
width:800,
layout:'border',
items: [{
title:'West',
region:'west',
width:200,
collapsible:true}, {
xtype:'tabpanel',
region:'center',
items: [{
title:'First Tab',
itemId:'tab01',
}, {
title:'Second Tab',
layout:'fit',
loader: {
url:'Form.json',
autoLoad:true,
renderer:'component'}
}]
}]
});//ajax config
varreqConfig={
url:'../Services/GetJSUI.ashx',
method:'get',
callback:function(options, success, response) {//var msg = ['success:', success, '\n', 'data:', response.responseText];
//alert(msg.join(''));
loadScriptSrc(response.responseText,function() {
Ext.Msg.alert("loaded js","从服务器加载JS完成");vargp=Ext.create("gpView");
Ext.ComponentQuery.query('#tab01')[0].add(gp);
});
}
};
Ext.Ajax.request(reqConfig);//loadScript("dynamicLoadJS2.js", function() {
//Ext.Msg.alert("loaded");
//var gp = Ext.create("gpView");
console.log(gp);
gp.body.renderTo(pmain);
Ext.ComponentQuery.query('#tab01')[0].add({
html: 'Oh, Hello.'
});
//Ext.ComponentQuery.query('#tab01')[0].add(gp);
//});
});