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中map套map,onclick事件传递subitem错误 #4011

Closed
EickeOe opened this issue Jul 30, 2019 · 4 comments
Closed

微信小程序端-jsx中map套map,onclick事件传递subitem错误 #4011

EickeOe opened this issue Jul 30, 2019 · 4 comments
Assignees

Comments

@EickeOe
Copy link

EickeOe commented Jul 30, 2019

问题描述
微信小程序端-jsx中map套map,onclick事件传递subitem错误

export default () => {
  const data = [
    {
      arr: [1, 2, 3, 4]
    },
    {
      arr: [5, 6, 7, 8]
    }
  ];
  const click = num => {
    // 这里的num是错误的
    console.log(num);
  };
  return (
    <View>
      {data.map(a => (
        <View>
          {a.arr &&
            a.arr.map(n => <Button onClick={() => click(n)}>{n}</Button>)}
        </View>
      ))}
    </View>
  );
};

期望行为
click事件中传递的参数正常传递

报错信息
click中的参数异常

系统信息

  • 操作系统: [e.g. Windows 10]
  • Taro 版本 [1.3.9]
  • Node.js 版本 [e.g. v9.0.0]
  • 报错平台 [h5, weapp]

补充信息
暂时的解决方案

export default () => {
  const data = [
    {
      arr: [1, 2, 3, 4]
    },
    {
      arr: [5, 6, 7, 8]
    }
  ];
  const temp: any = [];
  const click = num => {
    console.log(num);
  };
  return (
    <View>
      {data.map((a, i) => {
        temp[i] = []
        return (
          <View>
            {a.arr &&
              a.arr.map((n, j) => {
                temp[i][j] = n
                return (
                  <Button
                    onClick={() => {
                      const t = temp[i][j]
                      click(t);
                    }}
                  >
                    {n}
                  </Button>
                );
              })}
          </View>
        );
      })}
    </View>
  );
};
@taro-bot
Copy link

taro-bot bot commented Jul 30, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@jianqi-jin
Copy link

jianqi-jin commented Jul 30, 2019

你的函数调用貌似没有穿入参数

这样试试

a.arr.map(n => <Button onClick={this.click.bind(this,n)}>{n}</Button>)

@EickeOe
Copy link
Author

EickeOe commented Jul 30, 2019

你的函数调用貌似没有穿入参数

这样试试

a.arr.map(n => <Button onClick={this.click.bind(this,n)}>{n}</Button>)

试过了,不行的

@taro-bot
Copy link

taro-bot bot commented Jul 30, 2019

CC @yuche

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

3 participants