juicer模板引擎使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了juicer模板引擎使用相关的知识,希望对你有一定的参考价值。

http://www.juicer.name/


<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/juicer.js"></script>


页面模板

  <div class="refund-bottom" id="divRefundRecord"> </div>

<script id="tpl" type="text/template">
    {&each ObjectData as it,index}
    <div class="lectuer-info">
        <span class="photos"><img src="~/Content/images/pics/50x50.jpg"></span>
        <div class="cont">
            <span class="clearfix"><em class="fl-l">${it.UserId}</em><em class="fl-r">${it.CreateTime}</em></span>
            <span>${it.Explain}</span>
            <span class="leave-img"> </span>
        </div>
    </div>
    {&/each}
</script>


// 调用JS
    $(function () {
        GetList();
});

  function GetList()
    {
        var refundId = 100006;
        $.ajax({
            url: ‘/Refund/GetRefundRecordList‘,
            type: ‘POST‘,
            dataType: "json",
            data: { refundId: refundId },
            async: true,
            success: function (result) {
                $("#divRefundRecord").html(juicer($("#tpl").html(), result));
      //result是一个JSON对象, result.ObjectData 是一个数据集合属性,提供遍历模板使用
            }
        });
}

//后台代码
public ActionResult GetRefundRecordList(int refundId)
        {
            ResponseModel responseModel = new ResponseModel();
            using (var db = new BusinessEntities())
            {
                var RefundList = db.RefundRecord.Where(e => e.RefundId == refundId).Select(e => new {
                    e.UserId,
                    e.Explain,
                    e.CreateTime
                }).ToList();
                responseModel.ObjectData = RefundList;
                responseModel.IsSuccess = true;
                return Content(JsonConvert.SerializeObject(responseModel));
            }
        }

官网

http://juicer.name/

还有一个

https://github.com/aui/artTemplate

以上是关于juicer模板引擎使用的主要内容,如果未能解决你的问题,请参考以下文章

juicer模板引擎使用记录.md

Juicer 轻量级javascript模板引擎

js模板引擎之juicer,特别好用

前端模板Juicer

浅析js模板引擎

Javascript模板引擎插件收集