在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ jquery 在html 字符串里寫each 循環(huán)?

jquery 在html 字符串里寫each 循環(huán)?

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="./src/css/layui.css">
</head>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.js"></script>
<body>
    <div id="table"></div>
</body>
</html>
<script>
treeTabel({
    elem:'#table'
    ,cols: [[
      {checkbox: true,}
      ,{field:'id', title: 'ID', width:80, fixed: true}
      ,{field:'username', title: '用戶名', width:80}
      ,{field:'sex', title: '性別', width:80,}
      ,{field:'city', title: '城市', width:80}
      ,{field:'sign', title: '簽名', width:177}
      ,{field:'experience', title: '積分',  width:80}
      ,{field:'score', title: '評分', width:80}
      ,{field:'classify', title: '職業(yè)', width:80}
      ,{field:'wealth', title: '財富', sort: true, width:135}
    ]]
})
function treeTabel(data){
   var elem = $(data.elem);
   var cols = data.cols; //json
   var header= function(options){
    options = options || {};
    return ['<table cellspacing="0" cellpadding="0" border="0" class="layui-table">',
            '<thead><tr>',
            ''+ ($.each(cols,function(){'hello'})) +'',
            '</tr></thead>',
            '</table>' ].join("");
   }

   elem.append(header())
}
</script>

就這些代碼其實我可以new一個對象each 好。然后添加進這里 但是為了代碼精簡
我用這種方法寫怎么讓 return 里 $.each(cols,function(){'hello'}) 執(zhí)行花括號里的值 而不是直接輸入數(shù)組里的對象?

回答
編輯回答
巫婆

解決了 用
function(){
return }()
這種方式可以寫循環(huán)

2018年2月14日 18:34
編輯回答
幼梔
var colsArr = [];
$.each(cols, function(){colsArr.push()});

return [... + colsArr.join("") + ...].join();

代碼量少和代碼精簡應(yīng)該不是等價的

2017年9月18日 11:15