2012-06-19 124 views
0
var Song = Backbone.Model.extend({ 
    defaults: { 
     name: "Not specified", 
     artist: "Not specified" 
    }, 
    initialize: function() { 
     document.write("Music is the answer"); 
    }, 
    url:function(){ 
     return '/home/'; 
    } 
}); 

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]); 
document.write(myAlbum.models); // [song1, song2, song3] 
  1. 我如何發送myAlbum.models對象到我的服務。
  2. 我怎麼能提醒我的網址
+0

你是什麼意思有:_ 「提醒我的網址」 _? – fguillen

+0

重複? http://stackoverflow.com/questions/10782510/backbone-create-multiple-models-in-collection-serverside/10788855#10788855 – fguillen

+0

同意@fguillen。這是做批量更新/保存的解決方案。 http://stackoverflow.com/questions/5014216/best-practice-for-saving-an-entire-collection – TYRONEMICHAEL

回答