0
RESTSerializerを使用しており、モデル化するデータにロードできませんでした。RESTSerializerでデータを読み込むことができません
ここは私のコードスニペットです。
モデル/ sfresult.js:
import DS from 'ember-data';
export default DS.Model.extend({
sfresults: DS.hasMany('sfresults1', { async: false }),
//sfresults: DS.hasMany(),
message: DS.attr('string')
});
モデル/ sfresults1.js:
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string'),
caseNumber: DS.attr('string'),
lastModifiedDate: DS.attr('string'),
type: DS.attr('string'),
url: DS.attr('string'),
searchText: DS.attr('string'),
messageId: DS.attr('string'),
sfresult: DS.belongsTo('sfresult')
});
JSON応答:
{
"sfresult":{
"message":"SUCCESS",
"sfresults":[
{
"viewScore":"100.0",
"caseNumber":"000005462",
"id":"1d725883-15f2-4f18-927c-b14455440458",
"url":"url1",
"title":"title",
"description":"",
"lastModifiedDate":"12/29/16"
},
{
"caseNumber":"00007082",
"status":"Closed",
"id":"b79c0397-f544-45f0-8b91-e2bb7a386ebf",
"url":"ur2",
"title":"title1?",
"description":"",
"messageId":"500E000000DPA33IAH",
"lastModifiedDate":"08/16/16"
}
]
"id":"2b238d70-01ce-4604-913f-29d4c5eeba60"
}
}
シリアライザ/ sfresult.js
import RESTSerializer from 'ember-data/serializers/rest';
import DS from 'ember-data';
export default RESTSerializer.extend({
modelNameFromPayloadKey: function(payloadKey) {
if (payloadKey === 'sfresults') {
return this._super(payloadKey.replace('sfresults', 'sfresults1'));
} else {
return this._super(payloadKey);
}
},
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
let sfresults1 = payload.sfresult.sfresults;
let normalizedPayload = {
sfresults: sfresults1,
id: payload.sfresult.id,
message: payload.sfresult.message,
};
return this._super(store, primaryModelClass, normalizedPayload, id,
requestType);
},
});
コントローラ
let sfdata = this.store.query('sfresult',{ 'searchText':
inputSearchText, 'searchType' : 'SF' });
それはsfresult1モデルにデータをロードするが、それは次のエラーで失敗sfresult.js
にロードされていません。
Assertion Failed: The response to store.query is expected to be an
array but it was a single record. Please wrap your response in an
array or use `store.queryRecord` to query for a single record.
Error
at assert (http://localhost:8080/assets/vendor.js:16249:13)
at Object.assert (http://localhost:8080/assets/vendor.js:27921:34)
at assert (http://localhost:8080/assets/vendor.js:76154:37)
at http://localhost:8080/assets/vendor.js:86960:41
at tryCatch (http://localhost:8080/assets/vendor.js:69077:14)
at invokeCallback (http://localhost:8080/assets/vendor.js:69092:15)
at publish (http://localhost:8080/assets/vendor.js:69060:9)
at http://localhost:8080/assets/vendor.js:48963:16
at invoke (http://localhost:8080/assets/vendor.js:10885:14)
at Queue.flush (http://localhost:8080/assets/vendor.js:10953:9)
私はこの時点でこの時点で打たれました。どんな助けでも大歓迎です。