我从node.js提取了api数据并使用map循环了。我想检查类型值,如果类型值等于1,我想显示文本框,否则我想显示选择框。我该怎么做?请帮助我。
JSON
[
{
type: 1,
column_name: "uniname",
control_type: 2
},
{
type: 1,
column_name: "uni_short_name",
control_type: 2
},
{
type: 1,
column_name: "uni_mail",
control_type: 1
},
{
type: 1,
column_name: "ph_no",
control_type: 1
}
];
这里是代码
{this.props.validateType
? this.props.validateType.map((post, index) => (
<div key={index}>
<Checkbox
checked={this.state.checked[post.title]}
onChange={() => this.toggleChecked(post.title)}
>
{post.column_name}
</Checkbox>
{post.type == 1 ? (
<Input placeholder={post.column_name} />
) : (
<Select defaultValue="lucy" style={{ width: 120 }}>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="disabled" disabled>
Disabled
</Option>
<Option value="Yiminghe">yiminghe</Option>
</Select>
)}
</div>
))
: null}