创建骨干模型错误

时间:2013-08-17 09:08:16

标签: javascript backbone.js

我在backbone.js中很开心 当我用数据创建模型时,我有错误。

首先声明的模型如下;

var verifiedBookPriceSolutionApp = {
    Models :{},
    Collections : {},
    Views :{},
    Templates :{}
}

///BackBone model setting;
     verifiedBookPriceSolutionApp.Models.Journey = new Backbone.Model.extend({
         initialize: function(){}
     });

然后我创建一个模型如下,

    var journey = {"key": "0T", "carrier": "PS", "carrierName": "Ukraine International Airlines", "flight_number": "102", "origin": "AMS", "destination": "KBP", "departure_time": "2013-08-18T13:10:00.000+02:00", "arrival_time": "2013-08-18T16:55:00.000+03:00"}


var JourneyModel = new verifiedBookPriceSolutionApp.Models.Journey(journey);

在这一行中,我有一个错误,如“Uncaught TypeError:Object [object Object]没有方法'apply'”

我无法找到解决方案,为什么会出现这样的错误。

问候,

3 个答案:

答案 0 :(得分:0)

定义new模型时,请勿在{{1​​}}上调用Backbone.Model.extend。这样做:

Journey

答案 1 :(得分:0)

您在这里创建一个对象:

 verifiedBookPriceSolutionApp.Models.Journey = new Backbone.Model.extend({
     initialize: function(){}
 });

将其更改为:

 verifiedBookPriceSolutionApp.Models.Journey = Backbone.Model.extend({
     initialize: function(){}
 });

答案 2 :(得分:0)

而不是这一行,

    var JourneyModel = new verifiedBookPriceSolutionApp.Models.Journey(journey);

尝试以下行:

    var JourneyModel = verifiedBookPriceSolutionApp.Models.Journey.set(journey);

而不是

    verifiedBookPriceSolutionApp.Models.Journey = new Backbone.Model.extend({
     initialize: function(){}
 });

写得像

   verifiedBookPriceSolutionApp.Models.Journey = new Backbone.Model;