jtemplates使用+同内容列合并
function ImportStatistics(val, pros) { top.$.jBox.tip("导入已完成,正在统计整理导入的数据...", 'loading'); top.$.ajax({ type: "post", dataType: "json", data: { "val": val, "pros": pros }, url: "admin/ajax.aspx?oper=ImportStatistics&clienttime=" + (new Date().getTime()), error: function(XmlHttpRequest, textStatus, errorThrown) { alert(XmlHttpRequest.responseText); }, success: function(d) { switch (d.result) { case '-1': top.$.jBox.tip('未登录或者登录超时', 'error', { closed: function() { top.location.href = 'login.aspx'; } }); break; case '0': top.$.jBox.tip('' + d.returnval, 'error'); break; case '1': top.$.jBox.tip('' + d.returnval, 'success'); $("#result1").setTemplateElement("template"); // 给模板加载数据 $("#result1").processTemplate(d.table); for (var k = 3; k > 0; k--) { _w_table_rowspan("#dataresult", k); } break; } } }); }
function _w_table_rowspan(_w_table_id, _w_table_colnum) { // alert("1"); _w_table_firsttd = ""; _w_table_currenttd = ""; _w_table_SpanNum = 0; _w_table_Obj = $(_w_table_id + " tr td:nth-child(" + _w_table_colnum + ")"); _w_table_Obj.each(function(i) { if (i == 0) { _w_table_firsttd = $(this); _w_table_SpanNum = 1; } else { _w_table_currenttd = $(this); if (_w_table_firsttd.text() == _w_table_currenttd.text()) { _w_table_SpanNum++; // _w_table_currenttd.hide(); //remove(); _w_table_currenttd.remove(); _w_table_firsttd.attr("rowSpan", _w_table_SpanNum); } else { _w_table_firsttd = $(this); _w_table_SpanNum = 1; } } }); }
<!-- 模板内容 --> <textarea id="template" style="display: none"> <table id="dataresult" border="1"> <tr><td></td></tr> <tr><td></td></tr> <%-- <tr><th>项目</th><th>范围</th><th>要点</th><th>知识点</th><th>题量</th><th>单选题</th><th>多选题</th><th>判断题</th></tr> --%> <tr><th>项目</th><th>范围</th><th>要点</th><th>题量</th><th>单选题</th><th>多选题</th><th>判断题</th></tr> {#foreach $T as record} <tr align="center"> <td align="center">{$T.record.pname}</td> <td align="center">{$T.record.fwname}</td> <td align="center">{$T.record.ydname}</td> <%-- <td align="center">{$T.record.zsdname}</td> --%> <td align="center">{$T.record.count}</td> <td align="center">{$T.record.dancount}</td> <td align="center">{$T.record.duocount}</td> <td align="center">{$T.record.pancount}</td> </tr> {#/for} </table> </textarea> <!-- 输出元素 --> <div id="result1" style="float:left"> </div>