2
最終的な結果は、間に描かれているように、配列リストから生成された.jsファイル内に動的に作成される選択肢リストを作成したいと考えています。以下のコードの「オプション」部分。私はこの?:(REACT)アレイから動的選択オプションリストを作成する方法
const kvArray = [
{children: 'Country List', value: 0},
{children: 'France', value: 10},
{children: 'England', value: 20},
{children: 'Peru', value: 30}
].map ((keySelect, index) => ({
id: index,
name: keySelect,
}));
class FieldsPage extends React.Component {
onFormSubmit =() => {
const { dynamicFields, fields } = this.props;
const values = {
...fields.$values(),
concepts: {
...dynamicFields,
},
};
}
render() {
const { fields } = this.props;
const { disabled, error, submittedValues, selectValue } = this.state;
return (
<View>
<Form onSubmit={this.onFormSubmit}>
<Block>
<Select
{...fields.donation}
disabled={disabled}
label="Donation"
options={[
// What I want to happen here: build selection options by iterating through item, i.e.
{kvArray.map(item =>
{ children: item.name.children, value: item.name.value},
)}
]}
/>
</Block>
<Button disabled={disabled} type="submit">
<FormattedMessage {...buttonsMessages.submit} />
</Button>
</Form>
</View>
);
}
}