index.js(JS部分)
sportsZipSearch = () => {
const { zip1, dob1, age1, state1, check, count } = this.state;
const newArray = students.filter((el) => { return ((el.zip === zip1) && (parseInt(el.Age) <= parseInt(age1[Object.keys(age1)[0]])) || (el.sports_state != (state1)) && check ) });
const newArray1 = newArray[0].Sports_games.map((el1) => { return Object.keys(el1) });
//const sorted = newArray1[Object.keys(newArray1)].sort();
console.log(age1);
console.log(zip1);
console.log("here--", this.state.zip1, this.state.age1);
console.log(newArray);
console.log(newArray1);
//console.log(sorted);
console.log(newArray.Subjects);
console.log(count);
this.setState({ result: newArray, zipValue: true })
}
index.js(html部分)
Show list Sports: {result.length && result[0].Sports_games.map(g => { var visibility = (check && g[Object.keys(g)[0]]) ? 'block' : 'none'; return <div style={{display: visibility}}>{Object.keys(g)[0]} {g[Object.keys(g)[0]]}</div> } )}<br/><br/>
Show list Sports: {result.map(result_new => result_new.length && result_new.Sports_games.map(g => { var visibility = (check && g[Object.keys(g)]) ? 'block' : 'none'; console.log(visibility);return <div style={{display: visibility}}>{Object.keys(g)} {g[Object.keys(g)]}</div> } ))}<br/><br/>
答案 0 :(得分:0)
您应该创建一个在其props中使用这些值并显示它们的组件,然后使用map将数据数组转换为组件数组。然后将其放在所需的任何容器元素中。
赞:
function MyComponent() {
return (
<div>
<p>{props.data.name}</p>
<p>{props.data.age}</p>
</div>
);
}
然后将数据数组映射到组件数组:
my_component_array = my_data_array.map(d => <MyComponent data={d} />);