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组合使用编译出错 #318

Closed
zacksleo opened this issue Jul 14, 2018 · 1 comment
Closed

状态变量与map组合使用编译出错 #318

zacksleo opened this issue Jul 14, 2018 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@zacksleo
Copy link
Contributor

zacksleo commented Jul 14, 2018

复现步骤

在组件里面,状态变量与map组合使用时,编译出来后,结果不正确:

this.state.list[activeIndex].list -> var stateName = "list[activeIndex]";

这样编译后,并没有对 list 赋值

  render() {
    const activeIndex = this.state.activeIndex;
    const list = this.state.list[activeIndex].list.map((item) => {
      /*
      const cities = item.destination.split(',').map((city, index2) => {
        return index2 < 3 ? <Text>{city}</Text> : null;
      });
      */
      return this.state.list[activeIndex].type === 'trip' ?
        (
          <TripCard item={item} />
        ) : (
          <VisaCard item={item} />
        );
    });
    const tabs = this.state.list.map((item, index) => {
      return (
        <Text
          key={index}
          onClick={this.onClick}
          className={activeIndex === index ? 'active' : ''}
          data-index={index}
        >{item.name}
        </Text>
      );
    });
    return (
      <View>
        <View className="b_con">
          <Image className="head_b_c" src={labelImg} />
          <Text className="b_j">{this.props.title}</Text>
        </View>
        <View className="b_nav">{tabs}</View>
        <View className="boutique_fu">
          <View className="a active">{list}</View>
        </View>
      </View >
    );
  }

期望行为

在_createData里面,需要对 this.state.list[activeIndex].list 进行动态封装

报错信息

这里 stateName 不对,应该是动态进行赋值

        _this.$dynamicComponents = {
            $756388a7: function $756388a7() {
                var stateName = "list[activeIndex]";
                ...
                return {
                    stateName: stateName,
                    loopComponents: index_js_1.internal_dynamic_recursive(_this, nodes, index_js_1.internal_safe_get(_this.state, stateName), "$756388a7")
                };
            }
        };

系统信息

  • 操作系统: mac
  • Taro 版本: Taro v0.0.69
  • Node.js 版本: v8.11.1

补充信息
[可选]

如果把上面注释的代码(多余的),解注释,编译结果是正确的

@zacksleo zacksleo changed the title 状态变量与map组件使用编译出错 状态变量与map组合使用编译出错 Jul 14, 2018
@yuche yuche added the bug Something isn't working label Jul 14, 2018
@yuche yuche self-assigned this Jul 14, 2018
@wbget
Copy link

wbget commented Jul 15, 2018

遇到了同样的问题~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants