微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决仅在成功返回时删除骨干视图

我有一个骨干观点:

    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 举报,一经查实,本站将立刻删除。