我在访问模板中的路线模型时遇到了一些问题。我的模型作为我的家庭控制器中定义的操作的一部分成功创建:
actions: {
createProject: function () {
var project = this.store.createRecord('project', {
name: 'Sample name'
});
var self = this;
var promise = project.save();
promise.then(function (response) {
self.transitionToRoute('estimate', project);
});
promise.catch(function (errors) {
console.log(errors);
});
}
}
模型的 uuid 已正确序列化为 URL,我的 router.js 中的 URL 如下:
this.route('estimate');
this.route('estimate', { path: '/estimate/:project_id' });
我的estimate
控制器还正确指定了项目依赖项:
import Ember from 'ember';
export default Ember.Controller.extend({
needs: ['project']
});
...我在我的 routes/estimate.js 中定义模型如下:
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
// model: function(params) {
// return this.store.find('project', params.project_id);
// },
model(params) {
return this.store.findRecord('project', params.project_id);
}
});
记录this.store.findRecord('project', params.project_id)
我得到的输出:
Class {__ember1458995391969: null, __ember_meta__: Meta}
__ember1458995391969
...
但是,当我尝试访问我的估计车把模板中的项目模型(使用{{model.project.name}}
)时,我什么也没得到(没有错误,没有输出)。
有人对此有任何想法吗?