Javascript 主干绑定中存在此错误
这里是我的主干代码。查看。我在将方法绑定到DOM元素时遇到问题,console.log将其显示为我单击的DOM元素。我使用undescore方法\uBind来更正绑定,这是个什么问题?创建了一个新函数,它不会修改现有函数。你可以这样使用它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' ) |
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 )
}
});