主干模型:有没有办法区分初始保存事件和后续保存事件?
问题的标题几乎概括了这一点,我希望我的视图对模型实例初始保存与任何未来保存的响应不同。现在,我在保存之前获取模型的 isNew
attr,然后触发自定义事件,但我想知道是否有内置的东西?
The title of the question pretty much sums it up, I'd like my view to respond differently to a model instances initial save vs any future saves. Right now I'm grabbing the model's isNew
attr before I save and then triggering a custom event, but I was wondering if there was anything built in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查 model.isNew() 是判断初始保存是否已发生的内置方法。如果检查
isNew
对您有用,请继续这样做。初始保存应该为对象发出一个 ID,因此您可以将一个函数绑定到“change:id”,并且它将在初始保存成功后执行。或者您可以向
create()
的“成功”和“错误”回调添加逻辑。Checking
model.isNew()
is the built-in way of telling whether the initial save has happened yet. If checkingisNew
is working for you, keep on doing it.The initial save should issue an ID for the object, so you could bind a function to "change:id" and it would execute after the initial save succeeds. Or you could add logic to the "success" and "error" callbacks of
create()
.在这个答案的帮助下,我想出了以下内容解决方案:
我现在可以检查正在调用什么
方法
。With help from this answer, I came up with the following solution:
I can now check what
method
is being called.