2014-10-28 4 views
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가 정의되지 않았습니다.'

어떤 아이디어가 있습니까?

+0

에 대한 전망은 어디입니까? idAttributes를 설정 했습니까? – Muhaimin

+0

# item-template은 (tagName : 'tr')에 캡슐화되어 있습니다. 이름과 색은 속성이지만 id는 Parse에 의해 할당 된 objectId입니다. 두 속성 모두 올바르게 표시되지만 콘솔에 'ReferenceError : id is not defined'가 표시됩니다. – wraham

+0

['Parse.Object' 문서] (https://parse.com/)에'id' 속성에 대한 참조가 표시되지 않습니다. docs/js/symbols/Parse.Object.html). '시드'에 대해 말하는 게 아니겠습니까? – Dethariel

답변

1

id은 속성에 존재하지 않습니다. 실제로는 객체의 루트에 있습니다. 그래서 당신이해야 할 것입니다 무엇을 대신 this.model.attributes의 패스 _.template에 this.model()이며, 다음 HTML에 따라 조정 - 다음과 같은 :

render: function(){ 
    this.$el.html(_.template($('#item-template').html(), this.model)); 
} 

<td><%= id %></td> 
<td><%= attributes.name %></td> 
<td><%= attributes.color %></td> 
+0

감사합니다. 이미 다른 방법으로 해결했지만 솔루션이 더 좋습니다. – wraham

+0

다행입니다! :-) – jeffdill2

+0

궁금한데, 다른 해결책은 무엇입니까? – jeffdill2