我是靠谱客的博主 甜美冷风,这篇文章主要介绍dot.js的使用配合案例演示,现在分享给大家,希望可以做个参考。

dot.js在我所认为最重要的作用就是,我们再也不用繁琐的拼接字符串了

一.html

 <ul class="myul2">
</ul>

二.在js页面


var tpl = doT.template($("#area-list5").text());
var str = tpl(res.universityInfo.celebrityList);
$(" .myul2").html(str);

三.定义一个script


<script type="text/x-dot-template" id="area-list5">
<div class="swiper-container">
<div class="swiper-wrapper">
{{~ it:item:index}}
<div class="swiper-slide">
<li class="myli2">
<div class="myli2_top">
<img src="{{= item.headImg}}">
<span>{{= item.name}}</span>
</div>
<div class="myli2_center">
<p>{{= item.intro}}</p>
</div>
</li>
</div>
{{~}}
</div>
</div>
</script>

四.大功告成,再也不用拼接字符串了,前提要把dot.js引入

最后

以上就是甜美冷风最近收集整理的关于dot.js的使用配合案例演示的全部内容,更多相关dot.js内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(155)

评论列表共有 0 条评论

立即
投稿
返回
顶部