【发布时间】:2020-07-02 03:07:03
【问题描述】:
我在自己的 .ts 文件中定义了一个类型
export class FakeType {
value:{
name: string,
id: number
},
x: number
}
我在 .tsx 文件中有一个该对象的实例
let myObj: FakeType;
myObj = {
value:{
name: "Foo",
id: 99
},
x: 5
}
如何以编程方式创建与每个字段对应的 html 元素?
我可以手动创建我想要的输出,但如果FakeType 有数百个字段,这将不起作用
return (
<div>Value: {myObj.value}</div>
<div>x: {myObj.x}</div>);
请注意,当我在网页上显示字段名称及其值时,我需要访问它。
【问题讨论】:
-
使用
map函数?
标签: html reactjs typescript react-tsx