アルバムと曲の関係があります。同時に曲を求めている新しいアルバムビューで、最初にアルバムモデルを保存してから、曲のコレクションを保存してアルバムに添付しようとしています。
私の歌のコレクションの定義:
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);
}
});
ただし、A 'url' property or function must be specified
が返されますが、前に見たように指定されています。また、同期呼び出しの前にログに記録しようとしたところ、URL が正しく返されました。私はその過程で何かが欠けていますか?または、このように一度にすべての新しい曲をサーバーで作成することはできませんか?