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中的第二个参数如果命名成index编译有误 #2258

Closed
GrasFishs opened this issue Feb 25, 2019 · 3 comments
Closed

小程序map中的第二个参数如果命名成index编译有误 #2258

GrasFishs opened this issue Feb 25, 2019 · 3 comments
Assignees

Comments

@GrasFishs
Copy link

GrasFishs commented Feb 25, 2019

问题描述
[问题描述:小程序map中的第二个参数如果命名成index编译有误。当嵌套map时,第一层map中的索引命名为index时,在第二层中调用该index其实返回的是第二层map自身的索引]

复现步骤

// taro的 index.tsx
rooms.map((room, index) => (
  <View key={room.id}>
    <View>房间</View>
    <View className="men">
      {room.checkInMen.map(man => (
        <View onClick={this.handleRemoveMan.bind(this, man.id, index)}>
          {man.name}
        </View>
      ))}
    </View>
  </View>
);
<!-- 编译的index.wxml -->
<view wx:for="{{loopArray0}}" wx:for-item="room" wx:for-index="index">
  <view>房间</view>
    <view class="men">
      <view  data-e-tap-a-b="{{index}}" bindtap="handleRemoveMan" wx:for="{{room.$anonymousCallee__0}}" wx:for-item="man" data-e-tap-so="this" data-e-tap-a-a="{{man.$original.id}}">{{man.$original.name}}
      </view>
    </view>
  </view>
</view>

期望行为
[希望官方可以修复一下这个bug,或者在文档上有所提醒(困扰了一下午):joy:]

报错信息

[交互时因为索引不正确而移除错了对象]

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

  • 操作系统: [Windows 10]
  • Taro 版本 [v.1.2.4]
  • Node.js 版本 [v.8.12.0]
  • 报错平台 [weapp]

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]
小程序的index是默认的,Taro不会把命名成index的索引再次编译,所以用的就只是自身循环的索引。:p

@taro-bot
Copy link

taro-bot bot commented Feb 25, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@yuche
Copy link
Contributor

yuche commented Feb 25, 2019

也就是说在微信小程序中如果不说明 index 的变量名是啥,他会默认就叫 index?

@GrasFishs
Copy link
Author

就是微信小程序中的wx:for-index这个语法默认的是index。在Taro中,如果第二层map用到上一层map的索引,要是这个变量名为index,就会被Taro视为第二层自己的索引。

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

2 participants