Backbone——使用underscore template

1. 先定义转义符,因为默认的转义符<%= %> 与jsp的冲突      

    _.templateSettings = {

       interpolate : /\{\{(.+?)\}\}/g

    };

 

2. 在页面编写一个模版

    <script type="text/template" id="detailedBar-template">

        <div class='title'>

            <span class='label'>本次消费</span>

            <span class='numOfDinner'>{{numOfDiner}}人用餐</span>

            <span class='amount'><span class='symbol'>{{currencySymbol}}</span>{{amount}}</span>

        </div>

    </script>

 

3. 调用这个js模板

        var detailedBartemplate = _.template($('#detailedBar-template').html(),

            {numOfDiner: detailedInfo.numOfDiner, currencySymbol: self.currencySymbol, amount: detailedInfo.amount}

        );

        $detailedList.append(detailedBartemplate);

 

 

Thinking

调用时,_.template(,)的第二个参数位是指定传入模板的参数

 

注意代码的红色强调处

Uncaught TypeError: Cannot call method ‘replace’ of null (underscore.js:768)

You’re calling an underscore template put not passing in the data it uses in the template. You’re referencing an underscore template that doesn’t exist. You could have created a new template but forgot to change it’s id.

转载于:https://www.cnblogs.com/guancloud/archive/2013/01/20/2868309.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值