admin管理员组文章数量:1293705
In a WordPress SelectControl, instead of having fixed labels and values for options, how to put labels options out of a parsed json ?
e.g. myjson = {"A1":"1","A2","2} where A1 is the label and 1 is the value
<SelectControl
label="Asset id"
value={this.attributes.asset_id}
options=[{label: "Select one", value: null, disabled: true},
{label: "A1", value: "A1id"},
{label: "A2", value: "A2id"},
{label: "A3", value: "A3id"},
{label: "A4", value: "A4id"}]
onChange={(newval) => this.setAttributes({ asset_id: newval })}
/>
In a WordPress SelectControl, instead of having fixed labels and values for options, how to put labels options out of a parsed json ?
e.g. myjson = {"A1":"1","A2","2} where A1 is the label and 1 is the value
<SelectControl
label="Asset id"
value={this.attributes.asset_id}
options=[{label: "Select one", value: null, disabled: true},
{label: "A1", value: "A1id"},
{label: "A2", value: "A2id"},
{label: "A3", value: "A3id"},
{label: "A4", value: "A4id"}]
onChange={(newval) => this.setAttributes({ asset_id: newval })}
/>
Share
Improve this question
edited May 1, 2021 at 7:20
Dimitrios Ververidis
asked Apr 30, 2021 at 15:50
Dimitrios VerveridisDimitrios Ververidis
1426 bronze badges
1 Answer
Reset to default 2Never mind I found it.
let selectEntries = Object.entries(myjson).map( ([k, v]) => ({label: k, value: v}) );
本文标签: javascriptDynamically insert values in a WordPress SelectControl Options field
版权声明:本文标题:javascript - Dynamically insert values in a WordPress SelectControl Options field 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741583142a2386687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论