我正在構建我的第一個Backbone.js應用程序,並希望使用Handlebars插入我的數據。 我已經得到了backbone.View渲染確定,但{{變量}}沒有被與我通過在數據代替。Backbone.js與Handlebars.js不呈現選項
這是我的看法
OrderRow = Backbone.View.extend({
template: Handlebars.compile(
'<div class="orderContainer">' +
'<p class="row-top-container left">{{id}}</p>' +
'<p class="row-top-container right">{{time_stamp}}</p>' +
'<p class="row-top-container right">{{queue_time}}</p><br />' +
'<p class="items-contaier">{{items}}</p>' +
'</div>'
),
initialize: function(){
console.log("options used: " + this.options.sayHello);
this.render();
},
render: function(){
this.$el.html(this.template(this.options));
return this;
}
});
var data = {
id:657543,
name:"name"
}
var row = new OrderRow({ el: $('.row'), options:data });
這是DOM後視圖的被渲染
有誰知道我錯過了什麼? 任何幫助表示讚賞。
謝謝!
感謝您的支持!我還讓我的周圍Backbone.js的 只有一兩件事, 我傳遞將現包含數據的模型如你所說的頭,但我只獲得從模型中「身份證」。我沒有收到'time_stamp','queue_time'或'items'。 這是爲什麼? 再次,謝謝! – thehindutimes
模型將具有Handlebars將會看到的id屬性,其他屬性將位於其「屬性」屬性中。你通常會說'model.toJSON()'來獲取模板的數據。 –
太棒了,就是這麼做的。謝謝! – thehindutimes