【发布时间】:2017-03-07 13:24:11
【问题描述】:
我创建了 JSON 树的集合插入类型。
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(model.attributes.bathroom); 的console.log 语句
如何在 html 中使用 underscore.js each 访问该属性??
我真的很想要它的解决方案。
【问题讨论】:
-
我不确定我是否完全理解您的问题,但是您似乎不知道如何浏览模型属性的内部对象?
-
是的,你说的没错。
-
ok 是model.attributes一个数组还是一个对象?
-
我的模型是由对象组成的!
标签: javascript json backbone.js underscore.js underscore.js-templating