我正在为React.js在线学习一个关于受控输入的教程,并且我正在反复地获取错误
TypeError:无法读取未定义的属性“映射”
import CallRow from "./CallRow";
import React from "react";
class SearchPage extends React.Component {
constructor() {
super();
this.state = {
search: "Level Up"
};
}
updateSearch(event) {
this.setState({ search: event.target.value.substr(0, 20) });
}
render() {
return (
<div>
<ul>
{this.props.calls.map(call => (
<CallRow call={call} key={call.id} />
))}
</ul>
<input
type="text"
value={this.state.search}
onChange={this.updateSearch.bind(this)}
/>
</div>
);
}
}
export default SearchPage;
发布于 2019-09-12 06:50:25
似乎电话道具还没有定义。
在映射支柱值之前,检查它是否是未定义的。
请参阅以下代码:
<ul>
{(this.props.calls || []).map(call => (
<CallRow call={call} key={call.id} />
))}
</ul>
发布于 2019-09-11 22:24:44
您应该在调用props
时添加super
,而且您也没有显示整个应用程序逻辑,props.calls
甚至已经定义了吗?
class SearchPage extends React.Component {
constructor(props) {
super(props);
this.state = {
search: "Level Up"
};
}
...
发布于 2019-09-12 08:39:33
1检查是否将道具添加到组件SearchPage中,如
<SearchPage calls ={arry}/>
并单击此数组或不添加2
constructor(props) {
super(props);
在这个const {calls}=this.props;
为道具使用make之后,如果它通过使用的console.log(calls)
作为道具传递,那么检查调用的值。
https://stackoverflow.com/questions/57897520
复制相似问题