前端template.js模板⽤法
1.⾸先引⽤template.js然后在html中定义⼀个空的容器 class名为“quotation”
<div class="quotation"></div>
2.在script中定义ID名"template-quotation" 注意type type="text/template"
script 中可以把所有html标签包裹在内把从后台调取的值⽤<@=de@>的⽅式赋值
<script type="text/template" id="template-quotation">
  <span><@=de@></span>
</script>
3.ajax调⽤接⼝数据
$.ajax({
  headers: { token: Item('access_token') },
  type: "post",
  async: true,
  dataType: "json",
  data: { goods_type: goods_type },
  url: local + "Goods/goods",
  success: function(data) {
    console.log(data)
4.把获取到的数据通过template模板赋值给data 在上⾯取值即可
  $('.quotation').html(template($('#template-quotation').html(), {
    data: data
  }));
}
})
如需判断的情况如下
<@if(data.housingProperty==1 && data.isConfirm == 0){@>
  <div class="mui-bar mui-bar-tab posiBot-button">
  <button class="js-conform">⽅案确认</button>
</div>
如需循环的情况如下
<@if(data.lstDefectWAttachment.length>0){@>
script在html中的用法  <div class="photo">
  <@for(var i=0;i<data.lstDefectWAttachment.length;i++){var one=data.lstDefectWAttachment[i];@>
  <@if(one.attachmentSubType == 2){@>
  <img src="<@=one.attachPath@>"/>
  <@}else if(one.attachmentSubType == 3){@>
  <video controls preload="auto" poster="static/css/img/vidio-tu.png" src="<@=one.attachPath@>"></video> <@}@>
<@}@>
</div>
<@}@>
<@}@>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。