骨干提取过程

时间:2013-04-11 04:59:10

标签: javascript backbone.js backbone-model

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

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

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

我有一个带有data-id =“id from / static / js / public / json /”的按钮。

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')
        }
    }

});

如果我在获取后调试我的模型,它不会更新,但数据获取成功。 这可能是什么问题?

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

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

1 个答案:

答案 0 :(得分: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.')
            }
        });
    }
});