[英]Backbone.js Views bound to external model
Say ListTwoItemView
which is used to represent model ListTwoItem
, and that ListTwoItem
holds the ID of a ListOneItem
to which it is linked. 说ListTwoItemView
这是用来表示模型ListTwoItem
,并且ListTwoItem
持有的ID ListOneItem
到它链接。
If the user deletes a ListOneItem
, all ListTwoItem
's that link to it should be deleted. 如果用户删除ListOneItem
, ListTwoItem
删除所有链接到它的ListTwoItem
。 Does it make sense if I bind the ListTwoItemView
to the linked ListOneItem
so that should the referenced item be deleted - the ListTwoItem
model and view are also both removed? 如果我将ListTwoItemView
绑定到链接的ListOneItem
上是否有意义,那么是否应该删除引用的项目ListTwoItem
模型和视图也都被删除了?
No it doesn't. 不,不是。 Models do not know about views. 模型不了解视图。 What you normally do in that case is that your ListOneItem will destroy your ListTwoItem when it is destroyed itself. 在这种情况下,您通常会执行以下操作:ListOneItem在销毁自身时会销毁ListTwoItem。
This will raise a "delete" event on the collection the ListTwoItem is part of (if it is not part of anything, you must trigger an event yourself). 这将在ListTwoItem所属的集合上引发一个“删除”事件(如果它不属于任何内容,则必须自己触发一个事件)。 Listen to that event and remove/rerender the view as needed. 收听该事件,并根据需要删除/渲染视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.