我需要将一个id传递给一个集合以便在url中使用(例如/user/1234/projects.json),但我不知道如何做到这一点,一个例子会很精彩.
我的应用程序结构的方式是在启动时拉出并呈现"用户"的集合,然后我想在单击用户时将他们的"文档"从服务器拉到新集合中并在新视图中呈现.问题是将用户标识放入文档集合中以提供documents.fetch()的相关URL.
我想我已经知道了,这是一个例子:
//in the the view initialize function
this.collection = new Docs();
this.collection.project_id = this.options.project_id;
this.collection.fetch();
//in the collection
url: function() {
return '/project/api/' +this.project_id+'/docs';
}
Run Code Online (Sandbox Code Playgroud)