骨干模型属性

时间:2015-07-08 03:54:59

标签: javascript backbone.js

我有一个基本上看起来像这样的Backbone模型:

 var User = Backbone.Model.extend({


            idAttribute: "_id",

            givenName: 'UserModel',

            urlRoot: '/users',

            defaults: {
                firstName: null,
                lastName: null,
                username: null,
                password: null,
                email: null
            },

            initialize: function (options) {

                this.options = options || {};

                _.bindAll(this, 'deleteModel', 'persist', 'validate');


            },

            constructor: function (attributes, options) {
                Backbone.Model.apply(this, arguments);
            },

            validate: function (attr) {

                return undefined;
            },


            persist: function (adds, callback) {

            },
            deleteModel: function (callback) {


            }

        });

但是为什么在调试器中没有出现givenName?我认为这与Backbone的性质有关,而且我的代码或调试器没有任何问题。

enter image description here

这里我甚至是console.logged“model.givenName”,它确实是定义的。所以我不明白Backbone是如何工作的:

https://www.dropbox.com/s/h61xpl8st98wcqi/Screenshot%202015-07-07%2020.57.49.png?dl=0

enter image description here

0 个答案:

没有答案