下拉组件中的意外令牌

时间:2016-07-28 14:52:00

标签: javascript reactjs

我不断收到大括号开始的以下代码的意外令牌错误:

class Dropdown extends Component {
  render() {

    var types = ['normal', 'fire', 'water', 'electric', 'ice', 'fighting', 'poison', 'ground', 'flying', 'psychic', 'bug', 'rock', 'ghost', 'dragon'];

    return (
      <div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul className="nav navbar-nav">
          <li className="dropdown">
            <a href="#" className="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Organize By Type <span className="caret"></span></a>
            <ul className="dropdown-menu">
              {
                let list = types.map((type, index) => {
                  return (
                    <li key={index} onClick={this.onclick}>{type}</li>
                  )
                })
              }
            </ul>
          </li>
        </ul>
      </div>
    );
  }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如果有人遇到类似的问题,我就是这样做的:

    var types = ['normal', 'fire', 'water', 'electric', 'ice', 'fighting', 'poison', 'ground', 'flying', 'psychic', 'bug', 'rock', 'ghost', 'dragon'];

    var list = types.map((type, index) => {
      return (
        <li key={index} onClick={this.onclick}>{type}</li>
      )
    })

    return (
      <div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul className="nav navbar-nav">
          <li className="dropdown">
            <a href="#" className="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Organize By Type <span className="caret"></span></a>
            <ul className="dropdown-menu">
              {list}
            </ul>
          </li>
        </ul>
      </div>
    );
  }
}