Blog Category:
Jqueryajax Frame HTML
Phenomenon:
The HTML returned by Ajax cannot be automatically rendered as a Easyui style. For example: class= "Easyui-layout" etc.
Processing method:
After the HTML fragment has finished loading, use the
JS Code
- $.parser.parse (context)
Can be re-rendered.
Implementation principle:
First, attach the source code of Jquery.parser.js
JS Code
- (function ($) {
- $.parser = {
- Auto: true,
- plugins:[' LinkButton ',' menu ',' Menubutton ',' SplitButton ',' layout ',
- ' tree ',' window ',' dialog ',' the DataGrid ',
- ' combobox ',' combotree ',' Numberbox ',' Validatebox ',
- ' Calendar ',' Datebox ',' panel ',' tabs ',' accordion '
- ],
- Parse: function (context) {
- if ($.parser.auto) {
- For (var i=0; i<$.parser.plugins.length; i++) {
- (function () {
- var name = $.parser.plugins[i];
- var r = $ ('. easyui-' + name, context);
- if (r.length) {
- if (R[name]) {
- R[name] ();
- } Else if (window.easyloader) {
- Easyloader.load (name, function () {
- R[name] ();
- })
- }
- }
- })();
- }
- }
- }
- };
- $ (function () {
- $.parser.parse ();
- });
- }) (JQuery);
The framework defaults to rendering the entire document using $.parser.parse () automatically after the page is loaded.
1. jQuery Easyui Dynamic Add control or Ajax loading page does not automatically render problem resolution:
We can render the page successfully on the page, as long as the corresponding Easyui Class,easyui is written, because the parser is parser by default when the document is loaded ($ (document). Ready) is called once, and the entire page is rendered.
When the page is finished loading, however, if the DOM generated by JavaScript contains the class of the Easyui support control, for example, the following code is generated with javascript:
<a id= "tt" href= "#" class= "Easyui-linkbutton" data-options= "iconcls: ' Icon-search '" >easyui</a>
Although there is such a DOM on the page, but not to be rendered as Easyui LinkButton plug-in, because Easyui does not always listen to the page, so do not actively render, this time you need to manually call Easyui parser to parse.
Manual calls require attention to the following points:
The parse target is all descendant elements of the specified DOM and does not contain the DOM itself:
For example, the above code generated html,id= "TT" is what we want to LinkButton, like the following code to manually parse the words can not get the results you want:
$.parser.parse ($ (' #tt '));
The reason is simple, parser only the descendants of the TT, not including the TT itself, and its descendants do not contain any Easyui supported by the control class, so this place will not get the effect you want, it should be written like this:
$.parser.parse ($ (' #tt '). parent ());
All descendants of the parent node of the TT are rendered, and no matter what dom your JavaScript outputs, rendering the parent node directly will ensure that the page is parsed correctly.
----------------------------------------------
Try it, yes.
JQuery Easyui Dynamic Add control or Ajax loading page does not automatically render problem resolution