Javascript 主干-同步不';无法检测我的收藏url

Javascript 主干-同步不';无法检测我的收藏url,javascript,jquery,backbone.js,backbone-relational,Javascript,Jquery,Backbone.js,Backbone Relational,我有专辑和歌曲的关系。在“新建唱片集”视图中,我同时请求歌曲,我尝试先保存唱片集模型,然后保存歌曲集并将其附加到唱片集 我的歌曲集定义: define(function(require){ var Song = require('models/songModel'); Songs = Backbone.Collection.extend({ url: 'songs/', model: Song, }); re

我有专辑和歌曲的关系。在“新建唱片集”视图中,我同时请求歌曲,我尝试先保存唱片集模型,然后保存歌曲集并将其附加到唱片集

我的歌曲集定义:

define(function(require){
   var Song = require('models/songModel');

   Songs = Backbone.Collection.extend({
     url: 'songs/',         
     model: Song,           
   });

   return Songs;
});
我创建的歌曲集如下所示:

this.songCollection = new Songs();
//In some other view that saves the songs files and returns a hash
that.songCollection.add({title:file.name,song_file:response['file_hash']});
然后,我保存我的专辑型号,并成功尝试保存歌曲集,将新专辑pk添加到歌曲集中的所有型号:

that = this;
this.model.save(null,{                                 
    success: function(model,response){
       that.songCollection.each(function(song){                                                                                                     
          song.set('album',model.get('id'));
       });
       that.songCollection.sync('create');                                    
    },               
    error: function(response){                         
       console.log(response);                         
    }
 });

但是,它返回一个
必须指定一个“url”属性或函数
,但正如您前面所看到的,我确实指定了它。我还尝试在同步调用之前记录它,它会正确返回url。我在这个过程中遗漏了什么?或者我不能像这样一次在我的服务器上创建所有这些新歌?

您需要单独保存每首歌
sync
并不意味着直接调用,只有方法“read”意味着与集合一起使用
sync('read')
collection.fetch()期间被调用


尝试设置您的模型(不是集合)的“urlRoot”属性。我也尝试过,但它总是返回相同的错误。谢谢!这就是问题所在。我以为你可以一次保存整个收藏。
that = this;
this.model.save(null,{                                 
    success: function(model,response){
       that.songCollection.each(function(song){                                                                                                     
          song.save({album: model.get('id')});
       });                                   
    },               
    error: function(response){                         
       console.log(response);                         
    }
 });