我想在选中一行中的单选按钮时,将表格整行的值传递给函数.这是表格代码

<table className="table table-bordered table-stripped">
                <thead>
                    <th>AD Type</th>
                    <th>AD Title</th>
                    <th>Image/Video URL</th>
                    <th>Video Thumbnail</th>
                    <th>Landing URL</th>
                    <th>Placement</th>
                    <th>Country</th>
                    <th>DSP</th>
                    <th>Select</th>
                </thead>
                <tbody>
                    {
                        creative.map(
                            creative =>
                            <tr key = {creative.id}>
                                <td>{creative.ad_type}</td>
                                <td>{creative.ad_title}</td>
                                <td>{creative.image_url}</td>
                                <td>{creative.video_thumbnail}</td>
                                <td>{creative.landing_url}</td>
                                <td>{creative.placement}</td>
                                <td>{creative.country}</td>
                                <td>{creative.dsp}</td> 
                                <td> <input type="radio" class="checkbox1" id="chk" name="check[]" value={creative} onClick={func1} /></td>
                            </tr>
                        )
                    }
                </tbody>
            </table>

函数func1只记录值

const func1 = (e) => {
    console.log(e.target.value);
}

当我使用value = {creative}时,记录的输出是[object Object].

推荐答案

可以使用JSON.stringify()将对象值转换为JSON格式.

前任:

value{ JSON.stringify(creative) }

然后你试着得到你需要的值,用JSON.parse()来解析它

const func1 = (e) => {
  console.log(JSON.parse(e.target.value);
}

Javascript相关问答推荐

为什么getRecord()会因为与_logger相关的错误而失败?(使用Hedera SDK)

可以的.是否可以在不预编译的情况下使用嵌套 Select 器?

如何使用Echart 5.5.0创建箱形图

Exceljs:我们在file.xlsx(...)&#中发现了一个问题'"" 39人;

当试图显示小部件时,使用者会出现JavaScript错误.

未捕获错误:[]:getActivePinia()被调用,但没有活动Pinia.🍍""在调用app.use(pinia)之前,您是否try 使用store ?""

使用GraphQL查询Uniswap的ETH价格

Angular 中的类型错误上不存在获取属性

我创建了一个创建对象的函数,我希望从该函数创建的对象具有唯一的键.我怎么能做到这一点?

我怎么在JS里连续加2个骰子的和呢?

如何在ASP.NET项目中使用Google Chart API JavaScript将二次轴线值格式化为百分比

按下单键和多值

我想将Sitecore搜索面过滤器从多个转换为单个

如何在Press上重新启动EXPO-AV视频?

将基元传递给THEN处理程序

使用RxJS from Event和@ViewChild vs KeyUp事件和RxJS主题更改输入字段值

React Refs不与高阶组件(HOC)中的动态生成组件一起工作

如果我的列有条件,我如何呈现图标?

P5play SecurityError:无法从';窗口';读取命名属性';Add';:阻止具有源的帧访问跨源帧

如何将字符串拆分成单词并跟踪每个单词的索引(在原始字符串中)?