【发布时间】:2019-11-04 08:03:00
【问题描述】:
我有一个 JSON 对象要导入到类似于以下内容的反应页面中:
const obj1 = {
"January": [
{
"Id": 1,
"FileName": "some file",
"Format": "Excel (.xlsx)",
"Category": "some category 1",
"Start": "01/01/2019",
"End": "12/31/2019",
"Created": "01/09/2019"
},
{
"Id": 2,
"FileName": "some big file",
"Format": "Excel (.xlsx)",
"Category": "some category 2",
"Start": "01/01/2018",
"End": "12/31/2018",
"Created": "01/09/2019"
}
],
"February": [
{
"Id": 3,
"FileName": "some small file",
"Format": "PDF (.pdf)",
"Category": "some category 3",
"Start": "01/01/2018",
"End": "12/31/2018",
"Created": "01/09/2019"
},
{
"Id": 4,
"FileName": "some other file",
"Format": "Excel (.xlsx)",
"Category": "some category 4",
"Start": "01/01/2018",
"End": "12/31/2018",
"Created": "01/09/2018"
}
],
"March": [
{
"Id": 55,
"FileName": "some file again",
"Format": "Excel (.xlsx)",
"Category": "some category 5",
"Start": "01/01/2017",
"End": "12/31/2017",
"Created": "01/09/2017"
}
]
};
并且我想遍历上述对象并使用每个唯一类别动态填充选择下拉元素的选项。
选择看起来像这样:
<select className="selectpicker" data-width="fit" value="All" onChange={this.addSomeOptions}>
<option >Category 1</option>
<option >Category 2</option>
<option >Category 3</option>
</select>
有什么好办法吗?谢谢!
【问题讨论】:
-
标题有点难读,你的意思是一个数组,里面有生成值的函数数组吗?
标签: javascript arrays loops object