Code Monkey home page Code Monkey logo

easyadmin's Issues

关于表格列属性 templet 的函数参数说明

问题描述:

  • 渲染 table 的自定义模板 templet 属性的时候,比如渲染图片。在easyadmin 中可以使用 {templet: ea.table.image} 配置渲染 , 他会自动传入两个参数 data, option 。而在 layui 的 {templet: function(d){}} 配置的回调函数中只会传入第一个参数 d。请问 easyadmin 中他是怎么处理的,会传入2个参数...

问题解答:

  • 从结果上看

easyadmin 中修改了 layui.all.js 源文件 return "function" == typeof e.templet ? e.templet(l) : i(t(e.templet).html() || String(a)).render(l) 的 e.templet(l) 为 e.templet(l, e)

  • 具体分析

easyadmin 总计有两处 layui 2.5.6 源码修改:

  • src/lay/modules/table.js
parseTempData = function(item3, content, tplData, text){ //表头数据、原始内容、表体数据、是否只返回文本
    var str = item3.templet ? function(){
      return typeof item3.templet === 'function' 
        ? item3.templet(tplData, item3) // 改动处:此处需额外传入 item3 参数
      : laytpl($(item3.templet).html() || String(content)).render(tplData) 
    }() : content;
    return text ? $('<div>'+ str +'</div>').text() : str;
  }
  • src/layui.js
search: function(){
        var obj = {}
        ,search = (href 
          ? function () { var path = (href.match(/\?.+/) || [])[0] || ''; return path.replace(/\#.+/, '')} () // 改动处:此处增加#后面的字符串去除
          : location.search
        ).replace(/^\?+/, '').split('&'); //去除 ?,按 & 分割参数
        
       //代码省略...
      }()

Tips:

  • 修改源码后记得重新 gulp 打包
  • node 版本不能太高,否则会报 fs.js:42 } = primordials; 错误,因为 node 12.0 的版本之后(包括12.0版本)不支持 gulp4.0 之前的版本,实测本地使用 node11 没有报错, node16 就有问题
  • 这样重新打包后获得的 layui.all.js 文件就和 easyadmin 中的完全一样了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.