0

我有从服务器收集数据的主干模型:

Job.Models.Response = Backbone.Model.extend({
    defaults: {
    'authStatus': false,
    'id': '1',
    'name': 'name',
    },

        urlRoot: '/static/js/public/json/'
    });

我有 data-id =“来自/static/js/public/json/的id”的按钮。

Job.Views.Response = Backbone.View.extend({
    el: '.ra-response-button',

    events: {
        "click": "load"
    },

    load: function () {

        var info = this.$el.data();

        this.model.set({ id: info.id});
        this.model.fetch();

        if (this.model.attributes.authStatus === false) {
            console.log('Register')
        }
        else {
            console.log('Unregister')
        }
    }

});

如果我在获取后 console.log 我的模型,它不会更新,但数据获取成功。这里会出现什么样的问题?

这里我初始化我们的插件:

var responseModel = new Job.Models.Response;
var response = new Job.Views.Response({ model: responseModel });
4

1 回答 1

0

我解决了我的问题。最后查看。

    Job.Views.Response = Backbone.View.extend({
    el: '.ra-response-button',

    events: {
        "click": "load"
    },

    load: function () {
        var that = this;

        var info = that.$el.data();

        that.model.set({ id: info.id});
        that.model.fetch({
            success: function() {
                if (that.model.attributes.authStatus === true) {
                    new Job.Views.ResponseForm({ model: that.model })
                }

                else {
                    new Job.Views.ResponseAuth({ model : that.model })
                }
            },

            error: function() {
                alert('Error, repeat please.')
            }
        });
    }
});
于 2013-04-11T05:37:38.850 回答