在我的应用程序(React-typescript)中,我有一些类型的文档interface IDocument {id: string; questions: IQuestion[];}interface IQuestion {number: string; answer: string; }所以一系列文档看起来像是:doscuments: IDocument[] = [ {id: "a", questions: [ { number: "1", answer: "answer1" }, ... /* more number answer*/ ]}, {id: "b", questions: [ { number: "1", answer: "answer1" }, ... /* more number answer*/ ]}];现在我想将其转换为另一种类型的形式interface IAlternative { [key: string]: string;}具有ie的键值对alterDocs: IAlternative = {a1:"answer1", a2:"answer2",...,b1:"answer1",...}为此,我有下面的代码,但不能构造doc.id+question.number作为键和question.answer值的对documents.forEach(doc:IDocument=>{ doc.questions.forEach(question=>{ const pair= {} // I cannot construct this pair alterDocs={...alterDocs,...pair} })})
添加回答
举报
0/150
提交
取消