zoukankan      html  css  js  c++  java
  • 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"的元素  
  • 相关阅读:
    requests使用text可以查看源码
    正则表达式之search、sub
    【JS】深拷贝与浅拷贝的区别,实现深拷贝的几种方法
    php:对象(object)数据类型实例详解
    usage: git remote add [<options>] <name> <url> -f, --fetch fetch the remote branches --tags import all tags and associated objects when fetching
    PHP 可选参数
    php中文乱码问题的终极解决方案汇总
    html表单提交给PHP然后浏览器显示出了PHP的源代码
    wamp 安装
    wamp选择语言
  • 原文地址:https://www.cnblogs.com/sunjie9606/p/2683636.html
Copyright © 2011-2022 走看看