猿问

Taro-ui组件如何传值?

View层:

<View className='list'>
  {
    list.map((v, i) => (      <AtCard
        note='小Tips'
        extra='额外信息'
        title={v.title}
        thumb={v.image}
        key={v.id}
        data-id={v.id} // 想要传递的id
        onClick={this.gotoDetail}
      >
        {v.intro}      </AtCard>
    ))
  }</View>

事件获取传递的id失败!

gotoDetail = (e) => {    console.log(e)
    Taro.navigateTo({
      url: `/pages/detail/index?id=${e.currentTarget.dataset.id}` // 获取id失败
    })
  }

console:

请问如何获取循环中的id?


月关宝盒
浏览 587回答 1
1回答

白衣染霜花

onClick={this.gotoDetail.bind(this,&nbsp;v.id)}gotoDetail&nbsp;=&nbsp;(id)&nbsp;=>&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;Taro.navigateTo({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;`/pages/detail/index?id=${id}`&nbsp;//&nbsp;获取id失败 &nbsp;&nbsp;&nbsp;&nbsp;}) &nbsp;&nbsp;}
随时随地看视频慕课网APP

相关分类

Java
我要回答