首页 > 解决方案 > 我的函数如何知道我的 object.value,因为我传入了一个 void 参数?

问题描述

这是使用 Reactjs 创建组件的经典功能。

我还调用了一个函数来通过它们的“id”删除组件。我的组件使用解构数据。你会注意到我没有在我的函数调用中传递任何真正的参数,因为它是一个经典的争论“(id)”传递而不是解构参数“({id})”,我的函数如何知道我的对象的值? 因为删除有效!惊人。

这是我的功能:

  return( 
            this.props.data.element.map(({id, title}) => { 
                return( 
                    <li key={id} className="collection-item">
                        {title}
                        <i
                         className="material-icons"
                         // the delete will work ! 
                         // despite I pass a classic argument in 
                         onClick={() => this.onSongDelete(id)}
                        >delete</i>
                    </li>
                )
            })
        )

任何提示都会很棒,谢谢

标签: javascriptreactjsdestructuring

解决方案


推荐阅读