gpt4 book ai didi

reactjs - 将参数传递给当前导入的类

转载 作者:行者123 更新时间:2023-12-03 14:18:21 24 4
gpt4 key购买 nike

我正在使用grommet.io 作为用户界面。现在我已经处理了 ui,但我想将数据传递给函数来制作模态,所以我想传递 id 或其他参数。

我通过使用heading={heading}传递了它,但我无法使用alert读取它

import React from "react";
import ReactDOM from "react-dom";

import Box from "grommet/components/Box";
import Card from "grommet/components/Card";

import Layer from 'grommet/components/Layer';

class Note extends React.Component {

constructor(props) {
super(props)
this.showCardDetails = this.showCardDetails.bind(this)
}

showCardDetails = (e) => {
alert( (e.target.heading) )
}

render() {
const { heading, description } = this.props
return (
<Box flex={true} direction='row' justify='center' align='center' wrap={true} pad='small' margin='small' colorIndex='accent-1' value={heading} onFocus=''>
<Card heading={heading}
description={description}
textSize='medium' onClick={this.showCardDetails} contentPad='none' size='small' onFocus='' />
</Box>
)
}
}



export default Note;

最佳答案

由于 showCardDetailsNote 方法,因此它的 props 在那里可用,就像它们在 render 中一样:

  showCardDetails = (e) => {
const { heading, description } = this.props;
alert(heading);
}

关于reactjs - 将参数传递给当前导入的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52676732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com