我正在尝试将派生架构分配给对象。我想你会得到我想做的事情。这应该不是那么困难。我做错了什么?
let defaultValues = { 'apid': 1234, 'app': 'test' };
let hostFields = [
{
"name": "FirstName",
"required": true,
"label": {
"singular": "First Name"
}
},
{
"name": "LastName",
"required": false,
"label": {
"singular": "Last Name"
}
}
];
let appFields = ['FirstName', 'LastName', 'Bogus'];
let saveAll = [];
for (let i=0; i<hostFields.length; i++) {
let f = hostFields[i];
let save = defaultValues;
save.requiredByHost = 0;
save.requiredByApp = 0;
if (f.required === true) {
save.requiredByHost = 1;
}
if (appFields.indexOf(f.name) !== -1) {
save.requiredByApp = 1;
}
if (save.requiredByHost === 1 || save.requiredByApp === 1) {
save.schema = f;
saveAll.push(save);
}
});
console.log(saveAll);