JSrender渲染

来源:互联网 发布:yankee candle 知乎 编辑:程序博客网 时间:2024/06/01 12:25

更新后不刷新表单,使用jsrender渲染指定行数据。

1.在表格指定行处设置id
如果是只刷新某行数据,其他行保持不变,则需要在方法内传入该tr的index;
如果是条件查询出符合条件的tr,则不需传入index值。

<c:forEach var="item" items="${result}" varStatus="st">

st的值

<tr id="tr${st.index}">

调用更新方法时传index参数:

update(tr${st.index}')

ajax处采用jsrender渲染

//第九列$("#"+index).find("td").eq(9).remove(); //移除第九列后,后续列补上,则继续移除第九列$("#"+index).find("td").eq(9).remove();$("#"+index).append($.templates("#trInside").render({item: data.result, index: index}));

jsrender模板渲染

<script id="trInside" type="text/x-jsrender">        <td class="text-center">{{: item.inspectionCheckStatus}}</td>        <td align="center">        {{if item.inspectionCheckStatus=='Y'}}        <button class="btn btn-primary btn-sm" type="button" onclick="doUpdate('{{: item.waybillNo}}','{{: item.houseWaybillNo}}','N', '{{: index}}')">取消查验</button>        {{else item.inspectionCheckStatus=='N'}}        <button class="btn btn-primary btn-sm" type="button" onclick="doUpdate('{{: item.waybillNo}}','{{: item.houseWaybillNo}}','Y', '{{: index}}')">国检查验</button>        {{/if}}        </td></script>

或者

<script id="WaybillTableTemplate" type="text/x-jsrender">    <tr>        <td class="text-center">{{:waybillNo}}</td>        <td class="text-center">{{:origin}}</td>        <td class="text-center">{{:dest}}</td>        <td class="text-center">{{:fdate}}</td>        <td class="text-center">{{:ieDate}}</td>        <td class="text-center">{{:weight}}</td>        <td class="text-center">            <span class="glyphicon glyphicon-pencil" style="cursor: pointer;" title="修改" onclick="showWaybill('{{:waybillNo}}')"                data-toggle="modal" data-target="#modal"></span>            &nbsp;&nbsp; &nbsp;&nbsp;            <span class="glyphicon glyphicon-remove" style="cursor: pointer;" title="删除" onclick="del({{:waybillId}})"></span>        </td>    </tr></script>

有一点需要注意的是,jsrender渲染数据时,日期格式不正确。
要么在前端页面采用自定义函数规范格式,这种比较麻烦;
要么在dto规范日期格式。

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
0 0