更新:好的。我解決了這個問題..我認爲這是因爲我正在將新客戶端模板渲染到ClientsNewRoute的應用程序模板中(請參見下文)。我的理解(假設)是,它不在客戶端模型的上下文中操作,因爲它最初將新窗體呈現到應用程序模板中,然後在嘗試「transitionTo」客戶端列表視圖時將其視爲父窗體。emberjs transitionTo不呈現模型列表
我有一個客戶端視圖,列出所有的客戶端,當做一個完整的刷新,但從窗體中添加一個新的客戶端,並使用transitionTo它不會呈現列表。日誌顯示transitionTo成功,但我無法獲得列表來填充,除非我正在對客戶端/路由進行完整刷新。後端用一個完整的模型對象返回200。這可能是因爲模型掛鉤在從子路由轉換時未被調用。有任何想法嗎?
router.js
App.Router.map(function() {
this.resource('clients', function(){
this.route('new');
});
this.resource('client', { path: '/clients/:client_id' }, function(){
this.route('edit');
});
this.resource('managers', function(){
this.route('new');
});
this.resource('manager', { path: '/managers/:manager_id' }, function(){
this.route('edit');
});
this.resource('projects', function(){
this.route('new');
});
this.resource('project', { path: '/projects/:project_id' }, function(){
this.route('edit');
});
});
clients.route:
App.ClientsRoute = Ember.Route.extend({
model: function(){
return this.store.find('client');
}
});
客戶/ new_route.js:
App.ClientsNewRoute = Ember.Route.extend({
renderTemplate: function() {
this.render("clients/new", {
into: "application",
outlet: "main"
})},
model: function(){
return this.store.createRecord('client');
},
actions: {
create: function(client){
var route = this;
client.save().then(function() {
route.transitionTo('clients');
}, function() {
console.log('fail');
});
}
}
});
感謝
編輯:
客戶端/ new.handlebars:
<form {{action 'create' this on="submit"}} >
{{#if isSaving }}
saving record...
{{/if}}
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<h2>New Client</h2>
<table class="table table-striped">
<tr> <td> Company Name </td> <td>{{input class="form-control" type="text" value=company_name}} </td> </tr>
<tr> <td> First Name </td> <td> {{input class="form-control" type="text" value=first_name}} </td> </tr>
<tr> <td> Last Name </td> <td> {{input class="form-control" type="text" value=last_name}} </td> </tr>
<tr> <td> Email </td> <td> {{input class="form-control" type="text" value=email}} </td> </tr>
<tr> <td> Phone </td> <td> {{input class="form-control" type="text" value=phone}} </td> </tr>
<tr> <td> Description </td> <td> {{textarea class="form-control" value=description}} </td> </tr>
<tr> <td> Address </td> <td> {{input class="form-control" type="text" value=street_address}} </td> </tr>
<tr> <td> City </td> <td> {{input class="form-control" type="text" value=city}} </td> </tr>
<tr> <td> State </td> <td> {{input class="form-control" type="text" value=state}} </td> </tr>
<tr> <td> Zipcode </td> <td> {{input class="form-control" type="text" value=zip}} </td> </tr>
</table>
<button>Create</button>
</form>
</div>
<div class="col-md-2"></div>
</div>
clients.handlebars:
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<h2>Clients</h2>
<table class="table table-striped">
<tr>
<th>Company</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
{{#each}}
<tr>
<td>{{#link-to 'client' this}} {{company_name}} {{/link-to}}</td>
<td> {{ first_name}} {{last_name}} </td>
<td> {{ email }} </td>
<td> {{phone}} </td>
</tr>
{{/each}}
</table>
<p> {{#link-to 'clients.new'}}Create a new Client{{/link-to}}</p>
</div>
<div class="col-md-2">o</div>
登錄信息:
Transitioned into 'clients.new' ember.js?body=1:3499
Transition #1: TRANSITION COMPLETE. ember.js?body=1:3499
Attempting transition to clients ember.js?body=1:3499
Transition #2: clients.index: calling beforeModel hook ember.js?body=1:3499
Transition #2: clients.index: calling deserialize hook ember.js?body=1:3499
Transition #2: clients.index: calling afterModel hook ember.js?body=1:3499
Transition #2: Resolved all models on destination route; finalizing transition. ember.js?body=1:3499
Could not find "clients.index" template or view. Nothing will be rendered Object {fullName: "template:clients.index"} ember.js?body=1:3499
Transitioned into 'clients.index' ember.js?body=1:3499
Transition #2: TRANSITION COMPLETE
當我請求所呈現的模板直接路由是clients.handlebars並位於根目錄o f模板/目錄。它沒有插座,它包含顯示客戶端表的#each循環。
你可以張貼把手嗎?控制器是否有重要的意義 – claptimes
您需要提供「ClientsRoute」的信息,因爲那是有問題的區域。此外,這些定義爲地圖上的「路線」或「資源」? – gravityplanx
爲客戶端和客戶/新增路線以及車把模板添加路線。這裏唯一的出口是在我的application.handlebars文件中。 – errata