将值从backbone.js传递到后端

时间:2012-06-19 10:33:29

标签: javascript backbone.js

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. 我如何提醒我的网址

2 个答案:

答案 0 :(得分:0)

也许this post可以帮助你。

答案 1 :(得分:0)

将数据发送到后端,请执行以下操作:

myAlbum.save();

它向服务器发送POST(如果是新数据)或PUT(如果模型有id)请求。

更多: http://documentcloud.github.com/backbone/#Model-save