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. How do i send myAlbum.models object to my Service.
  2. How can i alert my url
John Cooper
  • 7,343
  • 31
  • 80
  • 100
  • What do you mean with: _"alert my url"_ ? – fguillen Jun 19 '12 at 10:37
  • duplicated? http://stackoverflow.com/questions/10782510/backbone-create-multiple-models-in-collection-serverside/10788855#10788855 – fguillen Jun 19 '12 at 10:43
  • Agree with @fguillen. Here is a solution to doing bulk updates/saves. http://stackoverflow.com/questions/5014216/best-practice-for-saving-an-entire-collection – TYRONEMICHAEL Jun 19 '12 at 13:19

2 Answers2

0

Maybe that this post can help you out.

Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
0

to send Data to the Backend do follwing:

myAlbum.save();

it`s sending a POST (if its new data) or a PUT (if model has id) request to the server.

for more: http://documentcloud.github.com/backbone/#Model-save

Moszeed
  • 1,037
  • 1
  • 10
  • 20