jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法

现象:

       AJAX返回的html无法做到自动渲染为EasyUI的样式.比如:class="easyui-layout" 等

处理方法:

      在html片段加载完毕后使用

Js代码  
  1. $.parser.parse(context)  

     即可重新渲染。

实现原理:

    首先附上jquery.parser.js的源码

Js代码  
  1. (function($){  
  2.     $.parser = {  
  3.         auto: true,  
  4.         plugins:['linkbutton','menu','menubutton','splitbutton','layout',  
  5.                  'tree','window','dialog','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);  

   框架默认在页面加载完成后自动使用$.parser.parse()对整个文档进行渲染

Js代码  
  1. $.parser.auto   //是否自动进行渲染  
  2. $.parser.plugins  //包含目前EasyUI框架中所有的插件名称  
  3. $.parser.parse(context)  
  4. //context  为待查找的 DOM 元素集、文档或 jQuery 对象,为空时默认为整个文档  
  5. //渲染对象为: class="easyui-pluginName"的元素  
原文地址:https://www.cnblogs.com/sunjie9606/p/2683636.html