2014-02-05 39 views
0

這是一個小的backboneJS程序 - 用Typescript編寫 - 我試圖根據模型中數據的變化觸發各種功能。當函數被觸發時,我很難讓觸發函數能夠訪問已經更改(添加,刪除,修改等)引起事件的模型實例。在這個小程序中,我做了一個小小的API調用e.change.get("answer"),我很確定這是錯誤的,但我無法找到正確的API調用。骨幹事件功能無法訪問導致事件的變化對象

class Answers extends Backbone.Collection { 

    constructor(options) { 
     super(options); 
     var self = this; 
     this.on("add", function (e) { 
      console.log("Added a new answer : " + e.change.get("answer")); // Need to access the newly added answer instance here 
     }, this); 
    } 

    model = Answer; 
} 

回答

0

你應該能夠

this.on("add", function (model) { 
     console.log("Added a new answer : " + model); 
    }); 

的第一個參數來訪問它是模型(見http://backbonejs.org/#Events-catalog

+0

這工作!謝謝。 – EternallyCurious

+0

如果答案是正確的,請接受它,以便其他用戶可以輕鬆找到正確答案。 –