0

컬렉션 내부에서 컬렉션 모델을 사용하는 이유는 무엇입니까?백본 컬렉션에서 모델을 사용하는 이유

예 :

var model = Backbone.Model.extend({ 
    url: '/rest/article/' 
}); 

var collection = Backbone.Collection.extend({ 
    url: '/rest/article', 
    model: model 
}); 
+0

가능한 중복 http://stackoverflow.com/questions/27448398/backbone-js-purpose-of-a-collection-with-a- 모델) –

답변

1
var model = Backbone.Model.extend({ 
    parse : function (response) { 
    // you can modify model 
    response.author || (response.author = 'Anonymous'); 
    return response; 
    }, 
    getArticleTitle : function() { 
    return this.get('author') + ' - ' + this.get('title'); 
    } 
}); 

var collection = Backbone.Collection.extend({ 
    url: '/rest/article', 
    model: model 
}); 

// you can access model methods 
collection.at(0).getArticleTitle(); 
[모델과 컬렉션의 Backbone.js 목적] (의
1

그래서 당신이 모델의 일종으로 인스턴스화 할 수 컬렉션에 항목을 추가 할 때마다.