簡體   English   中英

將數據推入余燼對象

[英]Pushing data into ember object

App.Friend = DS.Model.extend({
     fid: DS.attr("Number"),
     name: DS.attr("String"),
     bills: DS.hasMany("bill", {async: true})
});

App.Bill = DS.Model.extend({
     description: DS.attr("String"),
     amount: DS.attr("Number"),
     date: DS.attr("Date"),
     friend: DS.belongsTo("friend")
});

我的余燼應用程序中有以上兩種模型。 我的路線定義如下

 App.Router.map(function(){
     this.resource("friends", function(){
          this.resource("friend", {path: ":id"});
     });
 });

當我在朋友詳細視圖中時,我需要向特定的朋友添加賬單。 但是我無法在FriendController中控制該特定模型

App.FriendController = Ember.ObjectController.extend({
  actions: {
    addBill: function() {
        debugger;
    }
  }
});

在這種情況下,如何將帳單添加到特定朋友

我看不到路線,是否正在獲取模型?

App.FriendController = Ember.ObjectController.extend({
  actions: {
    addBill: function() {
      var model = this.get('model');
      model.get('bills').then(function(bills){
        bills.pushObject(.....); //Push it here
      });
    }
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM