Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Backbone.model:对象函数(a){returnnewn(a)}没有方法';拥有';_Javascript_Backbone.js_Requirejs - Fatal编程技术网

Javascript Backbone.model:对象函数(a){returnnewn(a)}没有方法';拥有';

Javascript Backbone.model:对象函数(a){returnnewn(a)}没有方法';拥有';,javascript,backbone.js,requirejs,Javascript,Backbone.js,Requirejs,我确实编写了以下代码(*) 当我尝试在js控制台中运行以下代码(**)时, 我得到以下结果: "your attributes are: ", Object // json object taken from the server as I was expecting Object function (a){return new n(a)} has no method 'has' 为什么我会遇到关于没有方法'has'的问题 - (**) (*) fetch是异步的,因此请尝试以下操作:

我确实编写了以下代码(*)

当我尝试在js控制台中运行以下代码(**)时,
我得到以下结果:

"your attributes are: ", Object // json object taken from the server as I was expecting  

Object function (a){return new n(a)} has no method 'has' 
为什么我会遇到关于
没有方法'has'
的问题

-

(**)

(*)


fetch
是异步的,因此请尝试以下操作:

require(["js/models/task"], function ( Model ) {
    var model = new Model({id: 1});
    model.fetch({success: function() {
        console.log(model.attributes);
    }});

});

如果我只注释
console.log(model.attributes)在您的代码中,我得到了相同的错误。所以问题就在我执行调用
model.fetch()时确定--是否包含下划线?这是backboneSure的一个依赖项。当然,可能是版本问题。版本->1.3.0;当前页面中的Backbone.VERSION“0.9.2:“Backbone唯一的硬依赖项是underline.js(>1.3.1)。”因此,肯定是这样。就在今天,我遇到了这种情况,将underline更新为最新版本修复了它。是的,这只是下划线版本的问题。
define([], function () {
    var MyModel = Backbone.Model.extend({

        initialize: function ()
        {
            this.bind("change", function () {
                console.log("this model has been changed")
            });

            this.bind("error", function (model, error) {
                console.log(error);
            })
        },

        urlRoot: "/",
        url: function () {
            var base = this.urlRoot || (this.collection && this.collection.url) || "/";
            if (this.isNew()) return base;
            return base + this.id;
        },

        validate: function (attribute) {
            if (typeof attribute === "object") {
                console.log("your attributes are: ", attribute);
            }
        }

    });

    return MyModel;
});
require(["js/models/task"], function ( Model ) {
    var model = new Model({id: 1});
    model.fetch({success: function() {
        console.log(model.attributes);
    }});

});