NodeJS:属性从响应中消失?
NodeJS: Properties disappearing from response?
在我的控制台中:
[ CampaignStrategy {
id: 248,
id_mm: 828419,
strategy_name: "Norhart_Encore_AUD",
impressions: 7623,
clicks: 13,
TEST_PROPERTY: '222222',
ordered_impressions:
Orderedimpression { ordered_impressions: '123', id: 7, strategy_id: 248 }
},
...
]
浏览器中收到的响应对象 (XHR):
[
{
"id": 248,
"id_mm": 828419,
"strategy_name": "Norhart_Encore_AUD",
"impressions": 7623,
"clicks": 13,
},
...
]
请注意 TEST_PROPERTY
和 ordered_impressions
如何不存在于后者中。我究竟做错了什么?
这是我的控制器逻辑:
@get('/campaignStrategies/{id}')
async findStrategies(
@param.path.number('id') id: number,
): Promise<any> {
const campaignStrats = await this.campaignStrategyRepository.find({
where: {
campaignId: id
}
});
const campaignStratsIds = campaignStrats.map(strat => {
return { strategy_id: strat.id }
});
const campaignSettings = await this.orderedimpressionRepository.find({
where: {
or: campaignStratsIds
}
});
const settingsTable = await campaignSettings.reduce((acc: any, setting: any) => {
acc[setting.strategy_id] = setting;
return acc;
}, {});
const fullData = campaignStrats.map((strat: any) => {
strat['TEST_PROPERTY'] = '222222'
strat['ordered_impressions'] = settingsTable[`${strat.id}`];
return strat;
});
console.log(fullData);
return fullData;
}
你应该试试:
const fullData = campaignStrats
.map((strat: any) => {
return {...strat, TEST_PROPERTY: 2222 /* and so on /* }
}
通过这种方式,您 return 一个与 campaignStrats
列表中的对象不同的对象。
PS:我不确定,为什么 console.log
向我们展示了错误的反应想法,也许有人会在这里发表评论或编辑。
在我的控制台中:
[ CampaignStrategy {
id: 248,
id_mm: 828419,
strategy_name: "Norhart_Encore_AUD",
impressions: 7623,
clicks: 13,
TEST_PROPERTY: '222222',
ordered_impressions:
Orderedimpression { ordered_impressions: '123', id: 7, strategy_id: 248 }
},
...
]
浏览器中收到的响应对象 (XHR):
[
{
"id": 248,
"id_mm": 828419,
"strategy_name": "Norhart_Encore_AUD",
"impressions": 7623,
"clicks": 13,
},
...
]
请注意 TEST_PROPERTY
和 ordered_impressions
如何不存在于后者中。我究竟做错了什么?
这是我的控制器逻辑:
@get('/campaignStrategies/{id}')
async findStrategies(
@param.path.number('id') id: number,
): Promise<any> {
const campaignStrats = await this.campaignStrategyRepository.find({
where: {
campaignId: id
}
});
const campaignStratsIds = campaignStrats.map(strat => {
return { strategy_id: strat.id }
});
const campaignSettings = await this.orderedimpressionRepository.find({
where: {
or: campaignStratsIds
}
});
const settingsTable = await campaignSettings.reduce((acc: any, setting: any) => {
acc[setting.strategy_id] = setting;
return acc;
}, {});
const fullData = campaignStrats.map((strat: any) => {
strat['TEST_PROPERTY'] = '222222'
strat['ordered_impressions'] = settingsTable[`${strat.id}`];
return strat;
});
console.log(fullData);
return fullData;
}
你应该试试:
const fullData = campaignStrats
.map((strat: any) => {
return {...strat, TEST_PROPERTY: 2222 /* and so on /* }
}
通过这种方式,您 return 一个与 campaignStrats
列表中的对象不同的对象。
PS:我不确定,为什么 console.log
向我们展示了错误的反应想法,也许有人会在这里发表评论或编辑。