반응형
What is a Collection?
- Backbone.js 의 Collection 은 Model 의 ordered set 이다.
var Song = Backbone.Model.extend({
initialize: function(){
console.log("Music is the answer");
}
});
var Album = Backbone.Collection.extend({
model: Song
});
Building a collection
var Song = Backbone.Model.extend({
defaults: {
name: "Not specified",
artist: "Not specified"
},
initialize: function(){
console.log("Music is the answer");
}
});
var Album = Backbone.Collection.extend({
model: Song
});
var song1 = new Song({ name: "How Bizarre", artist: "OMC" });
var song2 = new Song({ name: "Sexual Healing", artist: "Marvin Gaye" });
var song3 = new Song({ name: "Talk It Over In Bed", artist: "OMC" });
var myAlbum = new Album([ song1, song2, song3]);
console.log( myAlbum.models ); // [song1, song2, song3]
도움이 되셨다면 손가락 꾸욱~ ( 로그인 필요 x )
반응형
'프로그래밍 놀이터 > Web' 카테고리의 다른 글
[Script] jQuery Tutorial ( 기초 강좌 ) (0) | 2012.09.26 |
---|---|
[HTML] HTML DOM( Document Object Model ) Tutorial ( 기초강좌 ) (0) | 2012.09.25 |
[Script] Backbone.js Tutorial ( 기초 강좌 ) - Router (5) | 2012.09.25 |
[Script] Backbone.js Tutorial ( 기초강좌 ) - View (3) | 2012.09.24 |
[Script] Backbone.js Tutorial ( 기초 강좌 ) - Model (2) | 2012.09.24 |
댓글