我从WCF服务获得以下API响应,并且需要对其进行规范化以匹配API响应中的EnvironmentsList,FullEnvironmentsList和ServerTypeList对象。我需要帮助正确构建架构。
{
"EnvironmentList": {
"EnvironmentDTO": [
{
"ID": "77",
"Name": "SIT UAT02",
"Administrators": {
"UserDTO": [
{
"UserName": "user1"
},
{
"UserName": "user2"
}
]
},
"Servers": {
"ServerDTO": [
{
"ID": "269",
"Name": "web-u02"
},
{
"ID": "270",
"Name": "web-u04"
}
]
}
},
{
"ID": "93",
"Name": "SIT DEMO",
"Administrators": null,
"Servers": null
}
]
},
"FullEnvironmentList": {
"EnvironmentDTO": [
{
"ID": "77",
"Name": "SIT UAT02",
"Administrators": {
"UserDTO": [
{
"UserName": "user1"
},
{
"UserName": "user2"
}
]
},
"Servers": {
"ServerDTO": [
{
"ID": "269",
"Name": "web-u02"
},
{
"ID": "270",
"Name": "web-u04"
}
]
}
},
{
"ID": "93",
"Name": "SIT DEMO",
"Administrators": null,
"Servers": null
}
]
},
"ServerTypeList": {
"ServerType": [
"Unknown",
"Database",
"Web"
]
}
}
import { schema } from 'normalizr';
const environmentList = new schema.Entity('environments', {}, {idAttribute: 'ID'});
const fullEnvironmentList = new schema.Entity('fullenvironments', {}, {idAttribute: 'ID'});
const administrator = new schema.Entity('administrators', {}, {idAttribute: 'UserName'});
const server = new schema.Entity('servers', {}, {idAttribute: 'ID'});
environmentList.define({
EnvironmentDTO: [environmentList],
ServerDTO: [server],
UserDTO: [administrator],
});
fullEnvironmentList.define({
EnvironmentDTO: [fullEnvironmentList],
ServerDTO: [server],
UserDTO: [administrator],
});
export const environmentListSchema = {
EnvironmentList: environmentList,
FullEnvironmentList: fullEnvironmentList,
};
{
entities: {
environmentList: {
EnvironmentDTO: {
77: [...],
93: [...]
},
UserDTO: {
user1: [...],
user2: [...]
},
ServerDTO: {
269: [...],
270: [...]
}
},
fullEnvironmentList: {
EnvironmentDTO: {
77: [...],
93: [...]
},
UserDTO: {
user1: [...],
user2: [...]
},
ServerDTO: {
269: [...],
270: [...]
}
},
serverTypeList: {
ServerType: {
[...]
}
}
}
}
任何反馈将不胜感激。