Recently, I was building a EXTJS front-end framework, and the first toughest problem was loader.
Note that this is Componentloader, the function is to remotely request a page. Instead of Ext.loader, this is for dynamic load dependency.
During the resolution of the problem, Baidu, Google a lot of information about loader feel is not particularly useful, here I have encountered the problems recorded for your reference
First of all, I chose the Ext5.0.0 version, it should be a relatively new version of
1. Questions about normal Componentloader not executing script
var panel = ext.create (' Ext.panel.Panel ', { loader: { url:url, scripts:true, autoload:true, Loadmask:true }});
According to the API provided by the demo, we can easily write the above code, but in my development process, even if the configuration of Scripts:true, can not execute the URL page js, using a lot of methods can not solve the problem.
I finally rewritten the render method of the control and used the control's Update method to achieve the same effect as scripts:true.
The code is as follows:
var ctn = ext.create (' Ext.container.Container ', { id:id, title:title, closable:closable = = null? true:cl Osable, layout: ' Border ', loader: { listeners: { exception:function () { Ext.MessageBox.alert (" Hint "," page load exception, please contact Administrator ") } }, renderer:function (loader, response, active) { var text = Response.responsetext; Loader.gettarget (). Update (text, true); return true; }, callback:function (loader, success, response, options) { }, Url:url, Scripts:true, autoload:true, loadmask:true }});
As shown in the code, the HTML returned by the request is executed in render with the second parameter of the Update method, True, and rendered to the target control, CTN.
Note that the update here is equivalent to inserting a piece of executable HTML into the target control's subkey, which is why I chose container instead of panel because the Panel generates a panel and a panel-body two Div, So it will affect the execution of the update, so that the remote request HTML and Panel-body peer, resulting in HTML is not visible problems.
The above code snippet is only for those developers who have remote request pages and script does not execute, if scripts can be executed automatically, of course, do not need to superfluous, In fact, I do not understand this is not a 5.0 bug, but I switched to 4.2 seems to have this problem, there are experts can answer my doubts that is very good ~ ~
2. Remote Request Page Layout issues
We all know that loader is generally used to do menu and tab linkage, CTN is a remote request container, CTN's parent control is tabpanel-child, this I think we can understand. However, regardless of how ctn is laid out, the Panel that was requested remotely cannot be automatically laid out according to CTN layout.
CTN code has been posted above, the following is the code of the request page panel
var page = ext.create (' Ext.panel.Panel ', {region : ' Center ', layout: { type: ' table ', columns:2 } , Items:[gridpanel1,gridpanel2]
Renderto:parentid});
is a very simple code, CTN layout is border, in a nutshell, the page should automatically expand the full height of the parent control, but the fact is not. after the Update method executes the script for the remote page, the page is rendered to CTN via Renderto, and the fact is that this creates a layout problem.
Since CTN was first add to TabPanel, update, although the first in the add execution, but indeed asynchronous request, when the response to render, has not been properly laid out, I have tried updatelayout, and so on, as if it does not work
Finally, with the help of the historian, I added an add statement and removed the Renderto and changed the code to
var page = ext.create (' Ext.panel.Panel ', {region : ' Center ', layout: { type: ' table ', columns:2 } , Items:[gridpanel1,gridpanel2]}); EXT.GETCMP (ParentID). Add (page);
When the code executes to the last part of the remote sub-page, the dynamic Add this sub-page panel, I guess it should be in the Add source code to perform the re-layout or other aspects of the function, so solve this layout problem
I thought update was the function of add, but in fact it was not, although observing the HTML element would find that the element tree nodes were the same. But with a different class I can guess that the add actually performs the re-layout function.
Only by adding this last sentence can we associate the parent container with the remote sub-page, which is the top priority.
"ExtJS Study Notes" Ext.componentloader