JSrender渲染

更新后不刷新表单,使用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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值