JQuery Easyui Dynamic Add control or Ajax loading page does not automatically render problem resolution

Source: Internet
Author: User

Blog Category:
    • Jquery-easyui
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
    1. $.parser.parse (context)

Can be re-rendered.

Implementation principle:

First, attach the source code of Jquery.parser.js

JS Code
  1. (function ($) {
  2. $.parser = {
  3. Auto: true,
  4. plugins:[' LinkButton ',' menu ',' Menubutton ',' SplitButton ',' layout ',
  5. ' tree ',' window ',' dialog ',' the DataGrid ',
  6. ' combobox ',' combotree ',' Numberbox ',' Validatebox ',
  7. ' Calendar ',' Datebox ',' panel ',' tabs ',' accordion '
  8. ],
  9. Parse: function (context) {
  10. if ($.parser.auto) {
  11. For (var i=0; i<$.parser.plugins.length; i++) {
  12. (function () {
  13. var name = $.parser.plugins[i];
  14. var r = $ ('. easyui-' + name, context);
  15. if (r.length) {
  16. if (R[name]) {
  17. R[name] ();
  18. } Else if (window.easyloader) {
  19. Easyloader.load (name, function () {
  20. R[name] ();
  21. })
  22. }
  23. }
  24. })();
  25. }
  26. }
  27. }
  28. };
  29. $ (function () {
  30. $.parser.parse ();
  31. });
  32. }) (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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.