我创建了 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]);
}
}
});
关于javascript - 如何使用 underscore.js 每个循环渲染 TREE JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42649494/