Parse.com - Parse.Object.extend(...) attributes
Parse.com - Parse.Object.extend(...) attributes
我正在使用Parse JS和Backbone,并尝试打印Parse JS模型中的值列表。这很容易,但我对objectId有问题。
然后,我。。。
var Thing = Parse.Object.extend('MyThings');
var Things = Parse.Collection.extend({
model: Thing
});
var collection = new Things();
collection.fetch({
success: function(){
App.start(collection.toJSON());
}
});
这是视图。。。
ThingView = Backbone.View.extend({
tagName: 'tr',
render: function(){
this.$el.html(_.template($('#item-template').html(), this.model.attributes));
}
});
ThingListView = Backbone.View.extend({
tagName: 'table',
addAll: function(){
this.collection.forEach(this.addOne, this);
},
render: function(){
this.$el.empty();
this.addAll();
},
addOne: function(item){
var itemView = new ThingView({model: item});
itemView.render();
this.$el.append(itemView.el);
}
});
这是一个模板(使用Underscore.js)…
<script type="text/template" id="item-template">
<td><%= id %></td>
<td><%= name %></td>
<td><%= color %></td>
</script>
属性名称和颜色显示正确,但未定义"id'
知道吗?
问题是id不存在于属性中。它实际上生活在物体的根部。因此,您需要做的是将this.model传递到_.template()中,而不是将this.model.attributes,然后在HTML中进行相应调整,例如:
render: function(){
this.$el.html(_.template($('#item-template').html(), this.model));
}
<td><%= id %></td>
<td><%= attributes.name %></td>
<td><%= attributes.color %></td>
相关文章:
- JSON.parse没有'不能使用Javascript
- 如何在Parse中创建一对多关系
- 如何使用Windows8JSON.parse将JSON文本反序列化为日期类型
- parse.com类中指针中的查询指针
- Javascript JSON.parse not working
- 从Parse.com返回的格式化日期
- 当其他解析器认为意外的令牌有效时,json.parse会失败
- 无法将JSON.parse与JSON_encode中的结果一起使用
- 使用Parse.com查询制作新闻源
- 如何使用Parse.com JavaScript SDK上传图像
- 在JSON.parse Javascript中字符串化Java对象抛出错误
- JSON.parse,已经在try/catch块中,仍然抛出语法错误
- 在underscore.js中显示列表中的所有项目(使用Parse.com)
- 如何在没有jquery的情况下使用Papa Parse
- PARSE-处理并发请求
- 停止JSON.parse()从JSON字符串数据中删除尾随零
- 为什么我需要使用“;JavaScript键”;在node.js上使用parse时
- DOM Attributes and React
- Parse.com - Parse.Object.extend(...) attributes
- 使用Parse.Object.attributes安全吗