插曲:backbone中model的url和urlRoot以及collection的关系

作者: the5fire 标签: backbone urlRoot 发布: 2012-04-15 阅读: 12423
这两天抽空在写webchat,发现个以前没有注意到的问题,当你的model和collection一起使用的时候,所有的CRUD操作,都通过collection中定义的url来进行就可以了,model中只需要定义一个空的urlRoot属性就行了(但是不能没有urlRoot)。至于原因,看文档上关于collection的url的描述:

Set the url property (or function) on a collection to reference its location on the server. Models within the collection will use url to construct URLs of their own.

翻译成中文就是:

在collection中,设置一个url属性(或者方法)来指向对应在服务器上的地址,在collection中的models将会使用这个url来构建它们自己的url。

---- EOF ----

微信公众号:Python程序员杂谈

相关文章