我有一个事务组件,当新事务添加到提供其上下文的模型时,它不会自动更新。
如果我离开另一条路线并回来,它会呈现它吗?
dashboard.hbs
<h3>Recent Transactions</h3>
{{transaction-history transactions=transactions}}
组件/事务history.hbs
{{#each transaction in transactions}}
<tr>
<td>{{transaction.ref_number}}</td>
<td>{{transaction.date}}</td>
<td>{{transaction.recipient}}</td>
<td>${{transaction.amount}}</td>
</tr>
{{/each}}
我的仪表板控制器中的操作方法
actions: {
submitQuickSend: function(){
var self = this;
$.get('http://localhost:8080', {request: 'generic'}).then(function(response){
App.Transactions.push(App.Transaction.create({
id: '',
foo: 'bar'
}));
self.set('transactions', self.get('transactions'));
});
}
}
答案 0 :(得分:2)
您所要做的就是将push更改为pushObject
actions: {
submitQuickSend: function(){
var self = this;
$.get('http://localhost:8080', {request: 'generic'}).then(function(response){
App.Transactions.pushObject(App.Transaction.create({ // change to pushObject
id: '',
foo: 'bar'
}));
self.set('transactions', self.get('transactions'));
});
}
}
答案 1 :(得分:-1)
更改
{{transaction-history transactions=transactions}}
到
{{transaction-history transactionsBinding="transactions"}}