如何在我的标题属性中显示一个值?

问题描述 投票:0回答:2

有没有办法在我的Dropdown标签里面给我的title属性加一个值。例如,我想得到title='Lead'+{this.state.candidance}。我也在使用'rsuite'的Dropdown。

<Sidenav className="nav1-full" defaultOpenKeys={['1']} activeKey="1">
  <Sidenav.Body>
    <Nav className="nav-bar">
      <Dropdown className="nav1-body" eventKey="1" title="Lead">
        <Dropdown.Item eventKey="1-1" href="/candidates/1">
          Exploratory
        </Dropdown.Item>
        <Dropdown.Item eventKey="1-2" href="/candidates/2">
          Phone Intro
        </Dropdown.Item>
      </Dropdown>
    </Nav>
  </Sidenav.Body>
</Sidenav>
html reactjs jsx
2个回答
1
投票

由于{}里面的任何东西都是一个内联的JSX表达式,你可以这样做。

 title={"Lead" + this.state.candidate.length}

你也可以使用ES6的字符串插值template 字符与``(回标)和。${expr} ,像这样。

 title={`Lead${this.state.candidate.length}`}

希望能帮到你


1
投票

你需要用托架把你的道具包起来。{} 代号

在括号里你可以写任何javascript代码。

<Dropdown title={'Lead ' + this.state.candidate.length}>

ES6的方式。

<Dropdown title={`Lead${his.state.candidate.length}`}>

0
投票
   title={`Lead${this.state.candidate.length}`}

应该可以了


0
投票

试试这个。简单的 template string 解决办法。

 title={`WhateverYouWantHere`}
© www.soinside.com 2019 - 2024. All rights reserved.