I am getting error when i try to get data from json file at this line in my code selectedEmployee: employeeList.data.Table[0],
(当我在我的代码selectedEmployee: employeeList.data.Table[0],
这一行尝试从json文件获取数据时,出现错误)
TypeError: _employeeList_json__WEBPACK_IMPORTED_MODULE_2__.filter is not a function(TypeError:_employeeList_json__WEBPACK_IMPORTED_MODULE_2 __。filter不是一个函数)
//App.js(//App.js)
const filterEmployee = (searchText, maxResults) => {
return employeeList.filter((employee) => {
if (employee.data.Table.name.toLowerCase().includes(searchText.toLowerCase())) {
return true;
}
return false;
}).slice(0, maxResults);
}
var maxResults = 4;
export default class App extends React.Component {
constructor(){
super();
this.state = {
selectedEmployee: employeeList.data.Table[0],
filteredEmployee: filterEmployee('', maxResults)
}
}
onSearch = (event) => {
this.setState({
filteredEmployee: filterEmployee(event.target.value, maxResults)
});
}
onEmployeeClick = (employee) => {
this.setState({
selectedEmployee: {name: employee.name, info: employee.info, contact: employee.contact}
});
}
render() {
return (
<Col lg={8} md={7} sm={4} lgOffset={2}>
<Col lg={6}>
<HomePage onSearch={this.onSearch} employeeData={this.state.filteredEmployee} onEmployeeClick={this.onEmployeeClick}/>
</Col>
<Col lg={6}>
<EmployeePage selectedEmployee={this.state.selectedEmployee}/>
</Col>
</Col>
);
}
}
//my json file looks like this(//我的json文件看起来像这样)
{
"data": {
"Table": [
{
"id": "1001",
"name": "Alez",
"info": "Alez"
},
{
"id": "1002",
"name": "Baro",
"info": "Alez"
}
]
}
}
What i want to accomplish is using a different .json format.(我要完成的工作是使用其他.json格式。)
these was the orginal json file format(这些是原始的json文件格式)
[
{
"key": "t1",
"data":{
"name": "James",
"info": "Software Development",
"contact": {
"office": "781-000-002",
"mobile": "087-321-0292",
"sms": "617-000-002",
"email": "[email protected]"
}
}
}
]
I want to use these json file format instead and update my code(我想改用这些json文件格式并更新我的代码)
{
"data": {
"Table": [
{
"id": "1001",
"name": "Alez",
"info": "Alez"
},
{
"id": "1002",
"name": "Baro",
"info": "Alez"
}
]
}
}
ask by Kuku translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…