小编dig*_*ter的帖子

在模板上渲染骨干集合时无法获取模型的cid

我试图在使用mustache.js构建的模板上呈现主干集合.问题是我无法在模板中获得模型的cid.我的代码是

        <div class="phone span4">
            <h5> Phone Appointments</h5>
            {{ _.each(slots, function(slot) { }}
                {{ if(slot.aptType == "P"){ }}
                    <h6 cid="{{=slot.cid}}"  aptId="{{=slot.aptId}}"> {{=slot.beginTime}}  - {{=slot.endTime}} </h6>
                {{  }   }}
            {{  }); }}
        </div>
Run Code Online (Sandbox Code Playgroud)

从上面的代码中,我可以得到aptId,beginTime和end Time,但不是Cid.如何在模板上渲染模型时从集合中获取模型的Cid?

我从视图中看到的渲染方法如下所示

    render:function(){
    var template = _.template($("#slot-display-template").html());
    compiledTmp = template({slots: this.collection.toJSON()})
    this.$el.append(compiledTmp);
    }
Run Code Online (Sandbox Code Playgroud)

使用cid作为模型的唯一标识符也有任何缺点吗?

提前致谢 !!!

javascript templates mustache backbone.js

11
推荐指数
1
解决办法
3226
查看次数

标签 统计

backbone.js ×1

javascript ×1

mustache ×1

templates ×1