Ember数据路由与处理程序和api调用在不同的位置

时间:2015-11-30 02:57:25

标签: ember.js ember-data ember-cli

我是Ember开发的新手,并尝试使用连接到API的Ember数据构建Ember应用程序。

http://localhost:3000/api/panelists 位置的我的API返回

{  
   "panelists":[  
      {  
         "id":1,
         "secret":"",
         "isDisabled":"false",
         "disabledAt":"null",
         "isLocked":"false",
         "isSecretExpired":"false",
         "invalidAuthCount":"0",
         "givenName":"Sma",
         "middleName":"na",
         "surname":"ran",
         "avatarMimeType":"JPEG",
         "avatarFilePath":"/home/sample.jpeg",
         "createdAt":"2015-11-27T12:17:05.000Z",
         "isDeactivated":"false"
      }
   ]
}

现在在我的Ember应用程序中,此案例的模型处理程序位于以下位置: App_Root / app / panelists / model.js

具体所需路线位于以下路径 App_Root / app / directory / route.js

现在,如何使用模型 App_Root / app / panelists / model.js 以及路径 App_Root /点击API http://localhost:3000/api/panelists 应用/目录/ route.js吗

目前的实施: 的 route.js

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.store.findAll('panelists');
  },
});

在浏览器中收到以下错误:

WARNING: Encountered "panelists" in payload, but no model was found for model name "panelist" (resolved model name using golf-digest-panelists@serializer:-rest:.modelNameFromPayloadKey("panelists"))

Error while processing route: directory Assertion Failed: You must include an 'id' for undefined in an object passed to 'push' Error: Assertion Failed: You must include an 'id' for undefined in an object passed to 'push'
    at new Error (native)
    at Error.EmberError (http://localhost:4200/assets/vendor.js:24738:21)
    at assert (http://localhost:4200/assets/vendor.js:14639:13)
    at Object.assert (http://localhost:4200/assets/vendor.js:22040:34)
    at ember$data$lib$system$store$$Service.extend._pushInternalModel (http://localhost:4200/assets/vendor.js:72829:15)
    at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:72815:34)
    at http://localhost:4200/assets/vendor.js:67700:17
    at Object.Backburner.run (http://localhost:4200/assets/vendor.js:9710:25)
    at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:4200/assets/vendor.js:73042:33)
    at http://localhost:4200/assets/vendor.js:67697:15

提前感谢您的帮助

2 个答案:

答案 0 :(得分:0)

此路径App_Root/app/panelists/model.js对您的模型有误。它应该是App_Root/app/panelist/model.js而不是复数。此外,如果您未使用pod结构,则模型的公共路径为App_Root/app/model/panelist.js

答案 1 :(得分:0)

通过更改

删除复数
    [{
"seller": "hashim",
"sa": "10",
"name": "Kuzhina"
},
{
"seller": "kadri",
"sa": "1",
"name": "Majmuna"
},
{
"seller": "mood",
"sa": "4",
"name": "Karrika"
},
{
"seller": "muslim",
"sa": "1",
"name": "Xhama"
},
{
"seller": "muslim",
"sa": "15",
"name": "Kauqa"
},
{
"seller": "lule",
"sa": "2",
"name": "Stringa"
},
{
"seller": "huder",
"sa": "465",
"name": "Kreveta"
},
{
"seller": "Majmun",
"sa": "1",
"name": "Dollapa"
},
{
"seller": "muslim",
"sa": "680",
"name": "Historiku"
},
{
"seller": "muslim",
"sa": "1",
"name": "Netflix"
}

return this.store.findAll('panelists');