0

我是主干.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] has no method 'apply'”之类的错误

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

问候 ,

4

3 回答 3

0

定义模型时不要调用newon 。做这个:Backbone.Model.extendJourney

 verifiedBookPriceSolutionApp.Models.Journey = Backbone.Model.extend({
     initialize: function(){}
 });
于 2013-08-17T09:13:12.947 回答
0

您正在这里创建一个对象:

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

将其更改为:

 verifiedBookPriceSolutionApp.Models.Journey = Backbone.Model.extend({
     initialize: function(){}
 });
于 2013-08-17T09:13:50.563 回答
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;
于 2013-08-17T09:21:06.923 回答