属于不返回Ember中的值吗?

时间:2018-09-10 08:35:36

标签: ember.js ember-data

响应:

data:{type: "individuals", id: "xxx-xx-x--x--x",…}
attributes:{user_id: "xxx-xx-x--x--x", ces_user_id: "dsffdsf", first_name: "Test",…}
id:"xxx-xx-x--x--x"
relationships:{addresses: {data: [{type: "addresses", id: "0fe0e6ad-27a1-4e90-9d1f-034716f0ccc4"}]},…}
addresses:{data: [{type: "addresses", id: "0fe0e6ad-27a1-4e90-9d1f-034716f0ccc4"}]}
degrees:{data: [{type: "degrees", id: "2f00d21a-01dc-4391-8aca-a61491a2e7b8"},…]}
emails:{data: [{type: "emails", id: "e0166097-1e2f-4502-8fbc-7522a256c69a"},…]}
faxes:{data: []}
licenses:{data: [{type: "licenses", id: "294e19ac-a7f2-4316-9454-0b0b7276ebd9"},…]}
memberships:{data: []}
organizations:{data: [{type: "organizations", id: "c4178037-3ffc-4984-a317-9a489f2dca54"}]}
phones:{data: [{type: "phones", id: "c04d850b-0174-47f7-95ee-d01d7c51dbf0"}]}
user_image:{data: {id: 23811, type: "user_image"}}
data:{id: 23811, type: "user_image"}
id:23811
type:"user_image"
type:"individuals"
included:[
{type: "addresses", id: "0fe0e6ad-27a1-4e90-9d1f-034716f0ccc4",…},
{type: "emails", id: "e0166097-1e2f-4502-8fbc-7522a256c69a",…},
{type: "emails", id: "47de146a-00b5-4c4d-a492-5f865e14fd6a",…},
{type: "degrees", id: "2f00d21a-01dc-4391-8aca-a61491a2e7b8",…},
{type: "degrees", id: "2b131aec-79c7-4169-8fbc-68fc06aa7e6f",…},
{type: "phones", id: "c04d850b-0174-47f7-95ee-d01d7c51dbf0",…},
{type: "organizations", id: "c4178037-3ffc-4984-a317-9a489f2dca54",…},
{
attributes:{cloudinary-id: "dsfdfsfsddsfsdf", created: "2018-09-08T17:59:53+00:00", published: true,…}
id:23811
type:"user_image"
},
{type: "licenses", id: "294e19ac-a7f2-4316-9454-0b0b7276ebd9",…},
{type: "licenses", id: "21f0c34e-2a51-44b5-bd88-ad57bb28e066",…},
{type: "licenses", id: "43972613-a115-4f6c-937f-16ba823d70f3",…},
{type: "licenses", id: "75be099d-0926-4101-92db-e8e5eb283867",…},
{type: "institutions", id: "61EB6A22-3082-486A-B15E-96E976CD2289",…},
{type: "institutions", id: "339DF935-E3B1-41C5-A3E6-F53120C2856E",…},
]

在ember应用程序中,我得到了以上响应,但无法获取用户图像。我为用户图像创建了一个单独的模型,并将其与带有“到”关系的父模型“个人”相关联。有人可以帮忙吗?

model / individual.js

import Ember from 'ember'; 
import DS from 'ember-data'; 

export default DS.Model.extend({ 
firstName: attr('string'), 
middleName: attr('string'), 
lastName: attr('string'), 
terminateDate: attr('date'), 
addresses: hasMany('address'), 
emails: hasMany('email'), 
licenses: hasMany('license'), 
degrees: hasMany('degree'), 
organizations: hasMany('organization'), 
memberships: hasMany('membership'), 
phones: hasMany('phone'), 
faxes: hasMany('fax'), 
credits: hasMany('credit', { async: true }), 
userImage: belongsTo('user-image') 
});

searlizer / individual.js

export default DS.JSONAPISerializer.extend({ 
keyForAttribute(attr /* , method */) { 
return underscore(attr); 
}, 
normalize(modelClass, resourceHash) { 
const cesUserId = resourceHash.attributes.ces_user_id;

const creditsLink = { 
links: 
{ related: ENV.REC_ENGINE_URL + '/prof-users/' + cesUserId + '/credits' } 
}; 

resourceHash.relationships.credits = creditsLink; 
return this._super(...arguments); } 
}); 

0 个答案:

没有答案