如何在同一路径(在 ember 中)访问从模型钩子返回的模型数据?
how to access model data returned from model hook in the same route (in ember)?
项目的数据将在模板中编辑。如果我导航到其他 link willTransition 操作将不保存,将执行但如何在同一路线中访问 'project' 模型数据? (不使用控制器)
//routes/records/edit
return RSVP.hash({
project: this.get('store').findRecord('project', params.id),
..: this.get('store').findAll('...')
});
},
actions: {
willTransition(transition) {
if (project.isDirty) { //how to use project which is returned by model hook
if (!confirm('unsaved is it okay!!!')) {
transition.abort();
}
}
}
this.controller.get('model') 应该 return 模型,如果您在模型中设置 'project' 或者如果它是控制器 属性 那么可以被 this.controller.get('project')
访问
this.modelFor('record').project.get('hasDirtyAttributes');
.modelFor('record')
将从路由记录中获取模型,.project
将获取该模型内的RSVP,而.get('hasDirtyAttributes')
是模型数据的属性如果模型数据已更改,则设置为 true。
项目的数据将在模板中编辑。如果我导航到其他 link willTransition 操作将不保存,将执行但如何在同一路线中访问 'project' 模型数据? (不使用控制器)
//routes/records/edit
return RSVP.hash({
project: this.get('store').findRecord('project', params.id),
..: this.get('store').findAll('...')
});
},
actions: {
willTransition(transition) {
if (project.isDirty) { //how to use project which is returned by model hook
if (!confirm('unsaved is it okay!!!')) {
transition.abort();
}
}
}
this.controller.get('model') 应该 return 模型,如果您在模型中设置 'project' 或者如果它是控制器 属性 那么可以被 this.controller.get('project')
访问this.modelFor('record').project.get('hasDirtyAttributes');
.modelFor('record')
将从路由记录中获取模型,.project
将获取该模型内的RSVP,而.get('hasDirtyAttributes')
是模型数据的属性如果模型数据已更改,则设置为 true。