【发布时间】:2018-02-12 14:32:19
【问题描述】:
response : {initial_data: [{
"Did I see this plant in 2016?"=>"No",
"Did I see this plant in 2017?"=>"Yes",
"How Many?"=>1,
"User Data 4"=>"x",
"User Data 5"=>nil,
"Did I see this plant in 2022?"=>"No",
"Name"=>"Abronia alpina"},
{"Did I see this plant in 2016?"=>"No",
"Did I see this plant in 2017?"=>"No",
"How Many?"=>11,
"User Data 4"=>"x",
"User Data 5"=>nil,
"Did I see this plant in 2022?"=>"Yes",
"Name"=>"Abronia alpina1"}]
}
基于上述响应,我正在执行下面的代码以动态打印标题和值。
const CUSTOM_COLUMNS = (Object.keys(props.initial_data[0].map((item, index) => [{ id: 'user_data', Header: item, headerClassName: 'family-header', accessor: item, className: 'centered capitalize', show: true }][0] )); const columns = [ ...CUSTOM_COLUMNS, { Header: 'Actions', accessor: 'id', show: true, className: 'centered', Cell: (props) => ( <span className="label label-danger link" onClick={this.deletePlant.bind(this, props.value)}> <i className="fa fa-trash"></i> Delete </span> ) } ];
我能够正确地动态打印标题,但我的值不是动态的,而是在每一列中显示我最后一个哈希键值。
我的标题应该是:
["Did I see this plant in 2016?", "Did I see this plant in 2017?", "How Many?", "User Data 4", "User Data 5", "Did I see this plant in 2022?", "Name"]
并且行值应该是:
Row1 : ["No", "Yes", 1, "x", "", "No", "Abronia alpina"]
Row1 : ["No", "No", 11, "x", "", "Yes", "Abronia alpina1"]
您能否帮我动态获取它,或者让我知道我在这里做错了什么。我是新手,所以也许我在这里失踪了,所以请纠正我。
【问题讨论】:
标签: reactjs