我有一个模板 - editPerson.hbs
<form role="form">
FirstName: {{input type="text" value=model.firstName }} <br/>
LastName: {{input type="text" value=model.lastName }}
</form>
我想在用户想要编辑现有人或创建新人时呈现此模板。所以,我设置了路线:
App.Router.map(function(){
this.route("createPerson", { path: "/person/new" });
this.route("editPerson", { path: "/person/:id"});
// other routes not show for brevity
});
因此,我定义了两条路线 - 一条用于创建,一条用于编辑:
App.CreatePersonRoute = Ember.Route.extend({
renderTemplate: function(){
this.render("editPerson", { controller: "editPerson" });
},
model: function(){
return {firstName: "John", lastName: "Smith" };
}
});
App.EditPersonRoute = Ember.Route.extend({
model: function(id){
return {firstName: "John Existing", lastName: "Smith Existing" };
}
});
所以,我对模型进行了硬编码。我关注createPerson路线。我告诉它渲染editPersonTemplate并使用editPerson控制器(我没有显示,因为我认为它不重要 - 但我做了一个,但是。)
当我使用renderTemplate时,我丢失了模型John Smith,而后者又不会显示在网页上的editTemplate上。为什么呢?
我通过创建一个单独且相同的(to editPerson.hbs)createPerson.hbs并删除CreatePerson中的renderTemplate挂钩来“修复”它。它按预期工作,但我觉得为编辑和创建案例创建一个单独且相同的模板有点令人不安。
我到处寻找如何正确地做到这一点,我没有找到答案。