Javascript 从父级传递到子级的React方法未从子级触发

Javascript 从父级传递到子级的React方法未从子级触发,javascript,ajax,reactjs,Javascript,Ajax,Reactjs,父项:用户显示 子项:用户\项目\卡 你知道为什么removeItemFromDOM不是从用户\项\卡的不同ajax调用中触发的吗 其思想是从Rails数据库中删除模型。发生这种情况时,我使用removeItemFromDOM在父组件上触发forceUpdate,以便刷新子组件减去未链接的组件 用户展示: 用户\项目\卡: 可能是简单的打字错误吗?添加额外的“;”行吗帮忙 success: function(data){ alert('unlike successful!

父项:用户显示

子项:用户\项目\卡

你知道为什么removeItemFromDOM不是从用户\项\卡的不同ajax调用中触发的吗

其思想是从Rails数据库中删除模型。发生这种情况时,我使用removeItemFromDOM在父组件上触发forceUpdate,以便刷新子组件减去未链接的组件

用户展示:

用户\项目\卡:


可能是简单的打字错误吗?添加额外的“;”行吗帮忙

success: function(data){
            alert('unlike successful!');   // ADD ; HERE
            this.props.removeItemFromDOM() // HERE'S WHERE I'M ATTEMPTING TO FIRE THE METHOD PASSED DOWN FROM THE PARENT
        }.bind(this),
发现了一个解决方案:

当我将该方法作为道具传入时,上下文不正确。下面是UserShow父组件的render函数的工作原理:

render: function(){
    var that = this   // solution 
    var userItem = this.state.userItems.map(function(item){
        return <UserItemCard name={item.name} key={item.id} id={item.id} description={item.description} photo_url={item.photo_url} removeItemFromDOM={that.removeItemFromDOM}/> //notice the use of 'that'
    })
    return(
        <div>
            <Header img_src={this.state.headerImage} />

            <section className="body-wrapper">
                {userItem}              
            </section>
        </div>
    )
}

我还没有真正从DOM中删除元素,但至少该方法发出了警报。

感谢您查找@wintvelt。不幸的是,不是这样。
success: function(data){
            alert('unlike successful!');   // ADD ; HERE
            this.props.removeItemFromDOM() // HERE'S WHERE I'M ATTEMPTING TO FIRE THE METHOD PASSED DOWN FROM THE PARENT
        }.bind(this),
render: function(){
    var that = this   // solution 
    var userItem = this.state.userItems.map(function(item){
        return <UserItemCard name={item.name} key={item.id} id={item.id} description={item.description} photo_url={item.photo_url} removeItemFromDOM={that.removeItemFromDOM}/> //notice the use of 'that'
    })
    return(
        <div>
            <Header img_src={this.state.headerImage} />

            <section className="body-wrapper">
                {userItem}              
            </section>
        </div>
    )
}