あなたのユーザーコレクションのURLが/ユーザーに設定する必要があります。
は、ここでは一例であり、私はそれを持っていると思います。それが設定されると、あなたのモデルはその魔法を実行するためにそのURLを利用するべきです。モデルがコレクション内にある場合、 'url'メソッドを呼び出すと/ user /:idが返されると私は(完全に肯定的ではない)と信じています。だからあなたの典型的なREST-ish機能はすべて '/ user /:id'で利用されます。あなたが関係を持って何かをしようとしているなら(ユーザーは多くの文書を持っています)、それは一種のすすぎと繰り返しです。したがって、あなたのドキュメントコレクション(正しいユーザーに似ていますか?)では、urlに 'user_instance.url/documents'を設定します。
は(urlRootのためのバックボーン0.5.1へのアップグレード)、あなたはこのような何かをしたい基幹モデルとの一対多の関係を表示するには:
var User = Backbone.Model.extend({
initialize: function() {
// note, you are passing the function url. This is important if you are
// creating a new user that's not been sync'd to the server yet. If you
// did something like: {user_url: this.url()} it wouldn't contain the id
// yet... and any sync through docs would fail... even if you sync'd the
// user model!
this.docs = new Docs([], {user_url: this.url});
},
urlRoot: '/user'
});
var Doc = Backbone.Model.extend();
var Docs = Backbone.Collection.extend({
initialize: function(models, args) {
this.url = function() { args.user_url() + '/documents'; };
}
});
var user = new User([{id: 1234}]);
user.docs.fetch({ success: function() { alert('win') });
が私のために働きました。ありがとう! –