the5fire

关注Python、Django、Vim、Linux、Web开发、团队管理和互联网--Life is short, we need Python.


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

作者:the5fire | 标签:     | 发布:2012-04-15 11:38 p.m. | 阅读量: 11037, 10869
这两天抽空在写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。
- from the5fire.com
----EOF-----

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


其他分类: