2
저는 Parse JS와 Backbone을 사용하고 있는데 Parse JS 모델에서 값 목록을 인쇄하려고합니다. 간단하지만 objectId에 문제가 있습니다.Parse.com - Parse.Object.extend (...) attributes
는 다음, 나는 ...
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가 정의되지 않았습니다.'
어떤 아이디어가 있습니까?
# item-template은
['Parse.Object' 문서] (https://parse.com/)에'id' 속성에 대한 참조가 표시되지 않습니다. docs/js/symbols/Parse.Object.html). '시드'에 대해 말하는 게 아니겠습니까? – Dethariel
답변
id은 속성에 존재하지 않습니다. 실제로는 객체의 루트에 있습니다. 그래서 당신이해야 할 것입니다 무엇을 대신 this.model.attributes의 패스 _.template에 this.model()이며, 다음 HTML에 따라 조정 - 다음과 같은 :
출처
2014-11-28 17:50:15 jeffdill2
감사합니다. 이미 다른 방법으로 해결했지만 솔루션이 더 좋습니다. – wraham
다행입니다! :-) – jeffdill2
궁금한데, 다른 해결책은 무엇입니까? – jeffdill2
관련 문제