javascript - react 实现选项卡时怎么切换标题样式?
伊谢尔伦
伊谢尔伦 2017-04-11 11:33:08
[JavaScript讨论组]

我是看了网上的写法,用一个函数来返回样式名称, className={函数返回一个值}, 但是我这里整个函数被解析成了一个字符串,下面是代码:

    getClassName(index) {
        return index === this.state.currentLi ? style.style1 : style1.style2
    }

  render() {
    return(
      <p>
        <ul className={style.sideBar}>
          {
            React.Children.map(this.state.lists, (list, index) => {
              return(
                <li onClick={this.handlerClick.bind(this, index)} className={this.getClassName.bind(this, index)}> { list } </li>
              )
            })
          }
        </ul>
      </p>
    )
  }
  
  元素审查:
  

我应该怎么样才能得到函数返回的字符串?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
天蓬老师
this.getClassName.bind(this, index)()

改成这样试试.

话说,不用这么麻烦把.

React.Children.map(this.state.lists, (list, index) => {
              return(
                let style = index === this.state.currentIndex ? currStyle : normalStyle;
                <li onClick={this.handlerClick.bind(this, index)} className={style}> { list } </li>
              )
            })
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号