【发布时间】:2018-02-19 05:47:53
【问题描述】:
React js 新手在这里。我真的可以在以下问题上使用一些帮助和指导。 首先,我有 db.json,其中包括:
{
"applicants": [{
"id": 1,
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"coverLetter": "Aliquam ut nunc eu augue volutpat porta ullamcorper."
}, {
"id": 2,
"firstName": "Erica",
"lastName": "Hayfied",
"email": "erica@example.com",
"coverLetter": "Pellentesque habitant morbi tristique senectus."
}],
"skills": [{
"id": 1,
"description": "PHP",
"experienceInYears": 3,
"applicantId": 1
}, {
"id": 2,
"description": "JavaScript",
"experienceInYears": 3,
"applicantId": 1
}]
}
目前,下面的实现返回一个具有空技能集的申请人列表。我需要它来返回申请人及其相关技能的列表。
import { defaultMemoize, createSelector } from 'reselect';
import { get, filter, map, sortBy, } from 'lodash';
const getApplicants = createSelector(getApplicantIds, getApplicantsById,
(orderedIds, applicantsById) => map(orderedIds, id => applicantsById[id]));
* TODO: Actually merge related skills from the `state.skill` slice.
* @return {array} collection of applicants with their related skills included as a property.
*/
const getApplicantsWithSkills = createSelector(getApplicants,
applicants => {
const asApplicantWithSkills = applicant => ({
...applicant,
skills:[]
});
return map(applicants, asApplicantWithSkills);
});
我确信这是一个简单的解决方案,但我现在被卡住了,可能想多了。 Expected output
【问题讨论】:
-
请分享预期的输出
标签: javascript json reactjs react-native lodash