gpt4 book ai didi

javascript - 是否有用于查找数组中 json 对象的当前索引的函数?

转载 作者:行者123 更新时间:2023-11-30 14:02:54 25 4
gpt4 key购买 nike

在 onClick 时,我想记住 localStorage 中的名称,但我不知道如何将数组中的正确对象作为参数发送

myFunction(value){
console.log(value)
localStorage.setItem('name', value)
}

render() {
var { isLoaded, items} = this.state;

if (!isLoaded){
return <div>Loading...</div>
}else {
return (
<Container>

<Jumbotron>
<h1 align="center">The Clinicum</h1>
</Jumbotron>



<Row>
{items.map(row =>(
<Col key={row.iddoctor}>
<Image src= {require(`./photos/${row.photoLink}.jpg`)}
roundedCircle onClick={()
=> this.myFunction(this.state.items.name)} />
</Col>
))}
</Row>

如果我使用 this.state.items,console.log 会正确返回 hole json,所以其他一切都工作正常,这可能是一个愚蠢的问题,但我在 js 中很菜鸟,我找不到答案

最佳答案

这样做

myFunction(value){
console.log(value)
localStorage.setItem('name', value)
}

render() {
var { isLoaded, items} = this.state;

if (!isLoaded){
return <div>Loading...</div>
}else {
return (
<Container>

<Jumbotron>
<h1 align="center">The Clinicum</h1>
</Jumbotron>



<Row>
{items.map(row =>(
<Col key={row.iddoctor}>
<Image src= {require(`./photos/${row.photoLink}.jpg`)}
roundedCircle onClick={()
=> this.myFunction(row.name)} />
</Col>
))}
</Row>

关于javascript - 是否有用于查找数组中 json 对象的当前索引的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56003600/

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