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
Javascript 主干绑定中存在此错误_Javascript_Backbone.js_Underscore.js_Backbone.eventbinder - Fatal编程技术网

Javascript 主干绑定中存在此错误

Javascript 主干绑定中存在此错误,javascript,backbone.js,underscore.js,backbone.eventbinder,Javascript,Backbone.js,Underscore.js,Backbone.eventbinder,这里是我的主干代码。查看。我在将方法绑定到DOM元素时遇到问题,console.log将其显示为我单击的DOM元素。我使用undescore方法\uBind来更正绑定,这是个什么问题?创建了一个新函数,它不会修改现有函数。你可以这样使用它 DM.Backbone.View.feedback = Backbone.View.extend( { initialize: function (){ this.render( this.model.get( 'data' ) |

这里是我的主干代码。查看。我在将方法绑定到DOM元素时遇到问题,console.log将其显示为我单击的DOM元素。我使用undescore方法\uBind来更正绑定,这是个什么问题?

创建了一个新函数,它不会修改现有函数。你可以这样使用它

 DM.Backbone.View.feedback = Backbone.View.extend( {
     initialize: function (){
        this.render( this.model.get( 'data' ) || [] );
     },
     render: function ( param ){
        if ( $( '.problem_report_reply' ).length > 0 ) {
            _.bind( this.mail_to, this );
            $( '.problem_report_reply' ).off().on( 'click', this.mail_to )
        }
     },
     mail_to: function (){

        console.log( 'this', this )
     } );
或使用,它会修改对象中的函数

render: function ( param ){
    var func;

    if ( $( '.problem_report_reply' ).length > 0 ) {
        func = _.bind(this.mail_to, this);
        $('.problem_report_reply').off().on('click', func);
    }
}
DM.Backbone.View.feedback = Backbone.View.extend({
    initialize: function (){
        _.bindAll(this, "mail_to");
        this.render( this.model.get( 'data' ) || [] );
    },
    render: function ( param ){
        if ( $( '.problem_report_reply' ).length > 0 ) {
            $( '.problem_report_reply' ).off().on('click', this.mail_to)
        }
    },
    mail_to: function (){
        console.log( 'this', this )
    }
});