使用ember-data v1.0.0-beta.1-140-ga51f29c时出现gettng js错误

时间:2013-09-09 20:18:57

标签: ember.js ember-data

我正在尝试关注http://emberjs.com/guides/models/connecting-to-an-http-server/使用ember数据,但在创建其余的apis之后我得到的js错误如下:

加载路线时出错:

TypeError:数据未定义

代码:

Ember.assert(“您必须在传递给id的哈希中包含push”,data.id!= null);

我最初认为我需要在我创建的模型中包含“id”字段但是如果我这样做,则会抛出错误,说我不应该在模型中放入id字段。其余API的输出是正确的:

{
"analyticsRun": {
    "id": 1,
    "analyticsPlan": "some plan",
    "commandScript": "some script",
    "analyticsRunParameters": [
        "homeDir",
        "historyDir",
        "Sourcefolder",
        "resultsDir",
        "dataDir"
    ]
},
"analyticsRunParameters": [
    {
        "id": "homeDir",
        "default": "Some default",
        "description": "Where is the analytics folder",
        "name": "homeDir",
        "value": "Q:/Ember",
        "type": "global"
    },
    {
        "id": "historyDir",
        "default": "Rhistory",
        "description": "Where R image will be saved",
        "name": "historyDir",
        "value": "Rhistory",
        "type": "global"
    },
    {
        "id": "Sourcefolder",
        "default": "J:/Analytics_R_Source_Scripts",
        "description": "Where are source codes and functions are saved",
        "name": "Sourcefolder",
        "value": "J:/_R_Source_Scripts",
        "type": "type 1"
    },
    {
        "id": "resultsDir",
        "default": "results",
        "description": "Where are results stored",
        "name": "resultsDir",
        "value": "results",
        "type": "global"
    },
    {
        "id": "dataDir",
        "default": "Export",
        "description": "Where is raw csv stored",
        "name": "dataDir",
        "value": "Export",
        "type": "global"
    }
]
}

我的模型定义为:

AS.AnalyticsRun = DS.Model.extend({
'analyticsPlan' : DS.attr('string'),
'commandScript' : DS.attr('string'),
'parameters'    : DS.hasMany('analyticsRunParameter')
});

AS.AnalyticsRunParameter = DS.Model.extend({
'name'          : DS.attr('string'),
'type'          : DS.attr('string'),
'description'   : DS.attr('string'),
'default'       : DS.attr('string'),
'value'         : DS.attr('string')
});

我的路线是:

AS.AnalyticsConfigRoute = Ember.Route.extend({
model: function(param) {
    var store = this.get('store');
    return store.find('AnalyticsRun',param.runId);
}
});    

从错误看,代码正在进行id查找并且无法找到它。有没有人在此之前遇到过这个问题,或者您对如何解决这个问题有任何建议?

注意:isuse似乎是在_find函数的ember-data.js文件中引起的。

return resolve(promise).then(function(payload) {
Ember.assert("You made a request for a " + type.typeKey + " with id " + id + ", but the      adapter's response did not have any data", payload);
//payload has data here
payload = serializer.extract(store, type, payload, id, 'find');
//payload is undefined here!!
return store.push(type, payload);
}

谢谢, DEE

1 个答案:

答案 0 :(得分:1)

好的,所以我正在建立一个JSBIn,直到那时我会继续寻找问题(我对Ember模型更为熟悉)。

您是否尝试过在您的查找中将analyticsRun设置为小写?

 model: function(param) {
   var store = this.get('store');
   return store.find('analyticsRun',param.runId);
 }