循环生成cols中的templet可以使用Layui的Table模块的渲染方式和jQuery的循环方法。

首先,如果要使用Layui的Table模块,确保已经引入了Layui的相关文件。

接下来,可以使用jQuery的each方法来循环生成cols中的templet。

示例代码如下:

layui.use(['table'], function(){
  var table = layui.table;

  var cols = [
    {field: 'id', title: 'ID'},
    {field: 'name', title: 'Name'},
    {field: 'age', title: 'Age'}
  ];

  // 使用each方法循环生成templet
  $.each(cols, function(index, item){
    item.templet = function(d){
      return '<div>' + d[item.field] + '</div>';
    };
  });

  // 渲染表格
  table.render({
    elem: '#tableId',
    data: [],
    cols: [cols]
  });
});

在上述代码中,先定义了一个cols数组,其中包含了需要生成templet的字段和标题。然后使用each方法循环遍历cols数组,为每个字段添加templet属性,并定义templet的内容。最后,使用table.render方法渲染表格,其中cols参数传入cols数组。

这样,就可以循环生成cols中的templet了。

layui jquey循环生成cols中的templet