사용 "model.models는"나는 와인 저장고 응용 프로그램을 구축 백본 튜토리얼 http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/을 읽고 있어요. 이 튜토리얼의 저자는 한 점을 명확하게 설명하지 않고 설명서에서 알아낼 수 없습니다. 즉, 당신이 볼 수 this.model.models
의 사용은이보기에 대한 모델은 실제로 모음백본 :
list:function() {
this.wineList = new WineCollection();
this.wineListView = new WineListView({model:this.wineList});
입니다 그리고 컬렉션의 모델로 와인을 선언
window.WineListView = Backbone.View.extend({
tagName:'ul',
initialize:function() {
this.model.bind("reset", this.render, this);
},
render:function (eventName) {
_.each(this.model.models, function (wine) {
$(this.el).append(new WineListItemView({model:wine}).render().el);
}, this);
return this;
}
});
아래의 기능보기를 렌더링
window.WineCollection = Backbone.Collection.extend({
model:Wine,
url:"../api/wines"
});
WineListView가 인스턴스화되면 실제로는 Wine List Collection이 this.model
입니다. this.model
가 와인 컬렉션 (때문에 컬렉션 뷰에서 모델로 선언 된)이 이미 있다면, 문서에서, models
, 왜이다
modelscollection.models
Raw access to the JavaScript array of models inside of the collection. Usually you'll want to use get, at, or the Underscore methods to access model objects, but occasionally a direct reference to the array is desired.
그래서 콜렉션 내부 모델의 배열에 대한 액세스를 제공합니다 this.model.models
을 할 필요가 있습니까? 본질적으로 컬렉션을 다시 얻으려면? 이것은 본질적으로 문체의 선택처럼
흠. 백본 뷰는 뷰가 단일 객체가 아닌 콜렉션을 볼 때'model' 대신에 사용해야하는'collection' 프라퍼티를 가지고 있습니다. [코멘트 중 하나] (http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/#comment-27575)이 문제를주의 그러나 않습니다이 튜토리얼의 저자로부터 응답이 없었다. [Derick Bailey 's] (http://stackoverflow.com/users/93448/derick-bailey) 블로그 게시물은이 자료를 배우기에 더 좋은 장소 일 수 있습니다. –
@muistooshort 확인 덕분에, 내가 튜토리얼 작성자가 컬렉션을 개최 뷰의'model' 속성을 사용하기보다는 컬렉션을 개최'collection'를 사용하여 자신을 혼란 궁금 그 의견 .. – Leahcim