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

一个JSX元素中的不同事件绑定了同一方法时,后者的参数值会覆盖掉前者 #1299

Closed
tiancheng2000 opened this issue Nov 29, 2018 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@tiancheng2000
Copy link
Contributor

问题描述
一个JSX元素中的不同事件绑定了同一方法时,后者的参数值会覆盖掉前者

复现步骤
Taro代码,onTouchStartonTouchEnd 绑定了同名方法,最后一个参数值不同:

{groupedItems[seqLabelIdx].map( (item, itemIdx) => {
    return <View className='single-item-container' key={item._id_} 
        onTouchStart={this.showTooltip.bind(this, item.id, true)}
        onTouchEnd={this.showTooltip.bind(this, item.id, false)}>
        ......

编译得到的weapp代码(WXML),按目前的编译方法,将只能取到后一次绑定所用的参数值(false)

<view class="single-item-container" wx:key="{{item.$original._id_}}" 
  bindtouchstart="showTooltip" bindtouchend="showTooltip" 
  wx:for="{{seqLabelIdx.$anonymousCallee__0}}" wx:for-item="item" wx:for-index="itemIdx" 
  data-e-showTooltip-so="this" data-e-showTooltip-a-a="{{item.$original.id}}"
  data-e-showTooltip-a-b="{{false}}">
  ......

期望行为
能正确绑定两个不同的参数值,或许需编译成data-e-bindtouchstart-a-b(跟着事件名走),而非data-e-showTooltip-a-b(跟着方法名走)

报错信息

系统信息
Taro 1.1.3, NodeJs 10.9, weapp

@taro-bot
Copy link

taro-bot bot commented Nov 29, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam
Copy link
Member

目前是存在这个问题,暂时不太好解决,会在文档中注明一下

@luckyadam luckyadam added the enhancement New feature or request label Nov 29, 2018
@luckyadam luckyadam self-assigned this Nov 29, 2018
@tiancheng2000
Copy link
Contributor Author

恩,可以大致猜测到难处理的原因…
为了方法能找到参数,data-e-xxx-a-[a..z] 可以仍旧跟着方法名走,但把第一个参数的位置留给一个“切换器”?后面的参数,可以基于这个切换器前缀来寻找;当然这种Inner规则的改变也可能牵一发而动全身了🙏

@luckyadam
Copy link
Member

@tiancheng2000 对,后续考虑换一种实现方式

@taro-bot
Copy link

taro-bot bot commented Nov 30, 2018

CC @Chen-jj

@vimcaw
Copy link
Contributor

vimcaw commented Nov 30, 2018

Duplicate of #432

@Chen-jj Chen-jj closed this as completed Dec 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants