【发布时间】:2013-02-20 13:50:35
【问题描述】:
我想在创建帖子后进行转换。
post/new > 点击提交 > rails 后端成功创建帖子并响应一个 json > 重定向到新创建的帖子路径
在 ember_data_example github 源代码中。他们使用这种方法
transitionAfterSave: function() {
// when creating new records, it's necessary to wait for the record to be assigned
// an id before we can transition to its route (which depends on its id)
if (this.get('content.id')) {
this.transitionToRoute('contact', this.get('content'));
}
}.observes('content.id'),
很好用,因为模型创建时模型ID为null,模型保存成功后模型ID会发生变化,因为该函数会观察模型ID的变化。
但也许,只要模型的 ID 属性发生更改,就会执行此函数。 我正在寻找一些更语义化的方式。
我想要执行转换 当模型的状态变为 'isDirty' = false && 'isNew' == true form 'isDirty' = true, 'isNew' = false。
我该如何实现?
【问题讨论】:
标签: ember.js ember-data