仅在成功返回时删除骨干视图

问题描述

我有一个骨干观点:

    app.AircraftTypeView = Backbone.View.extend({
    tagName: 'div',className: 'Row view',template: actypetemplate,render: function(){
        this.$el.html( this.template(this.model.toJSON() ) );
        this.$input = this.$('.edit');
        return this;
    },initialize: function(){
        this.model.on('change',this.render,this);
    },events:{
        'click .delete' : 'deleteAircraftType','dblclick label' : 'edit','keypress .edit' : 'updateOnEnter','blur .edit' : 'close'
    },deleteAircraftType: function(){
        this.model.destroy(
        {
        wait: true,error: function(model,response) {
            var parsedmessage = JSON.parse(response.responseText);
            alert(parsedmessage.data.message);
            var parsedmessage = JSON.parse(response.responseText);
            },success: function(model,response){
   //        this.remove();    <<--- this undefined
            }
        })
    },edit: function(){
        this.$el.addClass('editing');
        this.$input.focus();
    },updateOnEnter: function(e){
        if(e.which == 13){
            this.close();
        }
    },close: function(){
        var title_value = this.$('#aircraft_type').val().trim();
        if(title_value){
            this.model.save({ "title": title_value },{error: function(model,response)       {alert(JSON.stringify(model))}});
        }
        this.$el.removeClass('editing');
    },}); 

我仅在成功从服务器返回后才想删除删除模型的视图。但是,“ this”不在回调函数的范围内。因此“ this.remove”不能在回调中使用。那么,如何触发“ this.remove”将模型从视图中删除

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)