Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map循环元素添加事件无效 #308

Closed
innocces opened this issue Jul 12, 2018 · 1 comment
Closed

map循环元素添加事件无效 #308

innocces opened this issue Jul 12, 2018 · 1 comment

Comments

@innocces
Copy link
Contributor

问题描述
在用map循环出的元素身上绑定的事件无效,无法触发

[或者可以直接贴源代码,能贴文字就不要截图]
源码

  navito = (info,e) => {
    console.log(info)
  }

  render () {
    let list = [1,2,3,4,5,6,7];
    return (
      <View className='index'>
        <Button className='add_btn' onClick={this.props.add}>+</Button>
        <Button className='dec_btn' onClick={this.props.dec}>-</Button>
        <Button className='dec_btn' onClick={this.props.asyncAdd}>async</Button>
        <View>{this.props.counter.num}</View>
        <View>Hello, World</View>
        <Icon size="20" type="success"/>
        {list.map((v,i)=>(<view className="viewsc" key={i} onClick={this.navito.bind(this,'循环view')}>{v}</view>))}
        <Button onClick={this.navito.bind(this,'button')}>button</Button>
        <View onClick={this.navito.bind(this,'单个view')}>测试事件</View>
      </View>
    )
  }
}

结果截图
default

报错信息

[这里请贴上你的完整报错截图或文字]

系统信息

  • 操作系统: [e.g. Windows 7]
  • Taro 版本 [e.g. v.0.0.69]
  • Node.js 版本 [e.g. v10.3.0]

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]
看了编译后的代码,onClick并没有编译成bindTap,如下
编译后的代码

<view class="viewsc" wx:key="{{i}}" onClick="navito" wx:for="{{list}}"
        wx:for-item="v" wx:for-index="i" data-e-navito-so="this" data-e-navito-a-a="循环view"
        data-component-path="{{$path}}">{{v}}</view>
@innocces
Copy link
Contributor Author

发现是自己view写成了小写

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant