Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应-无法读取属性';呼叫';未定义的_Javascript_Reactjs - Fatal编程技术网

Javascript 反应-无法读取属性';呼叫';未定义的

Javascript 反应-无法读取属性';呼叫';未定义的,javascript,reactjs,Javascript,Reactjs,除了添加新便条,这个小应用程序似乎一切正常。按钮位于板组件上 我知道这个问题通常是由于没有正确地绑定'this'的值造成的。我不确定这是问题所在,还是我遗漏了什么。谢谢 演示: /*jshint asi:true*/ 类注释扩展了React.Component{ 建造师(道具){ 超级(道具) this.state={editing:props.editing} } render(){ if(this.state.editing){ 返回此 }否则{ 返回这个。renderDisplay() }

除了添加新便条,这个小应用程序似乎一切正常。按钮位于板组件上

我知道这个问题通常是由于没有正确地绑定'this'的值造成的。我不确定这是问题所在,还是我遗漏了什么。谢谢

演示:

/*jshint asi:true*/
类注释扩展了React.Component{
建造师(道具){
超级(道具)
this.state={editing:props.editing}
}
render(){
if(this.state.editing){
返回此
}否则{
返回这个。renderDisplay()
}
}
编辑(){
this.setState({editing:true})
}
保存(){
this.props.changeHandler(this.refs.newText.getDOMNode().value,this.props.index)
this.setState({editing:false})
}
删除(){
this.props.removeHandler(this.props.index)
}
renderDisplay(){
报税表(
{this.props.children}

) } renderForm(){ 返回( 拯救 ) } } Note.propTypes={ 编辑:React.PropTypes.bool, onChange:React.PropTypes.func, onRemove:React.PropTypes.func } Note.defaultProps={编辑:false} 类板扩展React.Component{ 建造师(道具){ 超级(道具) this.state={ 注意:[{注意:'hi',id:this.nextId()}] } } 更新(新文本,i){ var arr=this.state.notes arr[i]。注意=newText this.setState({notes:arr}) } 删除(i){ var arr=this.state.notes 阵列拼接(i,1) this.setState({notes:arr}) } addNote(文本){ var arr=this.state.notes arr.push({ id:this.nextId(), 注:正文 }) 控制台日志(arr) this.setState({notes:arr}) } nextId(){ this.uniqueId=this.uniqueId | | 0 return++this.uniqueId } 各注释(注一){ 返回( {note.note} ) } render(){ 返回( {this.state.notes.map(this.eachNote,this)} ) } } 反应( , document.getElementById('留言板') )
绑定这对于
React
中的
ES6
类来说有些麻烦。一种方法是像这样将它们绑定到构造函数中

constructor(props) {
    super(props)
    this.nextid = this.nextid.bind(this)
    this.state = { 
        notes: [{note: 'hi', id: this.nextId()}]
    }
}
另一种方法是使用
babel.configure({stage:0})
和arrow函数

nextid = () => {}

你的代码很好。这可能是JSBin的一个bug,以及它如何处理Babel的透明。如果将pragma
//noprotect
添加到代码顶部,您将看到它是有效的。

我也遇到了同样的错误。我正在使用一个基本组件,我注意到我已经删除了基本组件的
componentDidMount
方法。当我调用sub-component中的super.componentDidMount时,它给出了错误。因此,我已取消超级呼叫,问题已解决。

感谢Janaka的回复。不幸的是,这似乎无法解决问题。我仍然收到此错误
TypeError:无法读取未定义的属性“call”
。似乎我可以使用setState()修改单个便笺(Board update())并从状态中删除便笺(Board remove()),但是,当我尝试将新便笺项添加到状态时,它会中断。Luke你就是那个人。如果我有更多的代表,我就能投票支持你的答案。谢谢没问题!当我们使用的工具不能为我们所用时,这总是一件令人沮丧的事。你应该考虑向JSB的Github RePo提交一个问题来引用这个问题。谢谢
nextid = () => {}