Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 主干事件函数无法访问导致事件的更改对象_Backbone.js_Typescript - Fatal编程技术网

Backbone.js 主干事件函数无法访问导致事件的更改对象

Backbone.js 主干事件函数无法访问导致事件的更改对象,backbone.js,typescript,Backbone.js,Typescript,下面是一个用Typescript编写的backboneJS小程序,我试图根据模型中数据的变化触发各种函数。当函数被触发时,我很难让被触发的函数能够访问引起事件的已更改(添加、删除、修改等)的模型实例。在这个小程序中,我进行了一个小的API调用e.change.get(“answer”),我很确定这是错误的,但我找不到正确的API调用 class Answers extends Backbone.Collection { constructor(options) { su

下面是一个用Typescript编写的backboneJS小程序,我试图根据模型中数据的变化触发各种函数。当函数被触发时,我很难让被触发的函数能够访问引起事件的已更改(添加、删除、修改等)的模型实例。在这个小程序中,我进行了一个小的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;
}

您应该能够使用访问它

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

第一个参数是模型(请参见)

如果答案正确,请接受它,以便其他用户可以轻松找到正确答案。