如何自动更新Ember组件的内容

时间:2014-02-28 18:37:16

标签: ember.js

我有一个事务组件,当新事务添加到提供其上下文的模型时,它不会自动更新。

如果我离开另一条路线并回来,它会呈现它吗?

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'));

    });
  }
}

2 个答案:

答案 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"}}