![](/img/trans.png)
[英]Backbone/underscore.js json to template with an each loop
[英]How to render is TREE JSON using underscore.js each loop?
我創建了JSON TREE的集合插入類型。
view.js
views.Livingword = Backbone.View.extend({
render: function(templateName) {
var template = _.template(templateName);
this.$el.html(template({result : this.collection.models}));
_.each(this.collection.models, function(model){
console.log(model.attributes.bathroom);
});
return this;
}
我想知道如何訪問model.attributes(即如何訪問每個對象?)
我輸入的console.log
語句類似於console.log(model.attributes.bathroom);
如何在HTML中使用underscore.js each
訪問此屬性?
我真的想要它的解決方案。
試試這個,也許這就是你想要的
_.each(this.collection.models, function(model){
console.log(model.attributes.bathroom);
for(var i in model.attributes){
if (model.attributes.hasOwnProperty(i)){
console.log(model.attributes[i]);
}
}
});
簡單地:
model.get('bathroom');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.