【发布时间】:2022-10-06 21:45:17
【问题描述】:
我有一个关于表单的对象数据数组:
const formFields = [
{
\"label\": \"Current Password\",
\"type\": \"password\",
\"name\": \"currentPassword\",
\"placeholder\": \"Current Password\",
\"required\": true
},
{
\"label\": \"New Password\",
\"type\": \"password\",
\"name\": \"newPassword1\",
\"placeholder\": \"New Password\",
\"required\": true
},
{
\"label\": \"Confirm New Password\",
\"type\": \"password\",
\"name\": \"newPassword2\",
\"placeholder\": \"Confirm New Password\",
\"required\": true
},
]
我有使用数组的组件:
return (
<Form>
{
formFields.map(function(data) {
return
<Form.Group className=\"mb-3\">
<Form.Label>{ data[\"label\"] }</Form.Label>
<Form.Control type={ data[\"type\"] } name={ data[\"name\"] } placeholder={ data[\"placeholder\"] } required={ data[\"required\"] } />
</Form.Group>;
})
}
<Button variant=\"primary\" type=\"submit\">
Submit
</Button>
</Form>
)
我在页面上看到的只是一个按钮。没有表单标签和表单域。假设 map 函数应该从对象数组formFields 创建一个元素数组。但是,它并没有这样做,并且其中的 return 语句的颜色是浅色的,就像它从未执行过一样。
-
因为如果 return 在它自己的行上,它会认为你想返回 undefined。所以你永远不会来到 Form.Group 部分
-
是 React 的东西还是 JavaScript 的东西?
标签: reactjs