material-ui:从onClick()处理程序中的Chip组件获取标签

时间:2019-04-28 22:14:42

标签: javascript reactjs material-ui

--Material-UI / React / Redux--

我有一个HTML("""<video width="480" height="270" controls><source src="{0}"></video>""".format(white_output))``` I want to run the video "project_video.mp4" through VideoFileClip and first get back an initial_image. Latter the video has to be processed by the code under the call and return final_image. The intention is that the very first frame of the processed video "project_video_Solution_SK_new.mp4" is initial_image and the rest are made up of final_image stitched together. I've gotten the syntax messed up because didn't understand how class functions. great full for any feedback 表。在每个material-ui内部有一些<TableRow>组件和自己的<TableCell>组件。这些<Chip>组件通过<Chip>属性呈现文本。

我需要能够在label处理程序内部提取标签,在我的例子中,该处理程序是onClick函数。

我将使用该标签来过滤我的redux状态,并为呈现该表的较大组件返回新数据。

点击处理程序

chipFilter()

组件渲染

表中呈现的每一行:

chipFilter = () => {
     console.log(this)
     console.log(this.props)
     console.log(this.props.label)
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

一个简单的解决方案是更新您的onClick处理程序,使包含单击的n的元数据的<Chip>对象像这样传递给chipFilter()

<Chip label={n.procedure} variant="outlined" color="primary" clickable={true}
      onClick={ () => this.chipFilter(n) } />

然后按如下所示更新chipFilter函数:

/* Item argument contains data for clicked chip component */
chipFilter = (item) => {
     console.log(this)
     console.log(item)
     console.log(item.label)
}