阵营,引导导航activeKey不会将NavItem的状态变为有效
问题描述:
<Nav pullRight activeKey={1}>
<NavItem eventKey={1} href="#" active>技术秘籍</NavItem>
<NavItem eventKey={2}>生活点滴</NavItem>
<NavItem eventKey={3} href="#">休闲娱乐</NavItem>
<NavItem eventKey={4} href="#">沟通交流</NavItem>
<NavItem eventKey={5} href="#">关于博主</NavItem>
</Nav>
我想的第一个项目是活动时,它的最初,但活跃并没有做什么,有没有人知道为什么阵营,引导导航activeKey不会将NavItem的状态变为有效
答
你是通过在第一个NavItem上指定“active”来覆盖你的activeKey值。
有效设置“activeKey = {1}”即可实现您所要求的功能。但是,这也意味着你将道具硬连线到1,所以它永远不会改变。
你真的想大概是什么东西,包括本地状态,即:
const Navigation = React.createClass({
getInitialState() {
return {activeKey: 1};
},
handleSelect(selectedKey) {
this.setState({activeKey: selectedKey});
},
render() {
return (
<Navbar fixedTop>
<Navbar.Header>
<Navbar.Brand>
<a className="page-scroll" href="#page-top" onClick={this.handleSelect.bind(null, 0)}>Some Brand</a>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav bsStyle="pills" activeKey={this.state.activeKey} onSelect={this.handleSelect}>
<NavItem eventKey={1} href="#">Link</NavItem>
<NavItem eventKey={2} href="#">Link</NavItem>
<NavItem eventKey={3} href="#">Link</NavItem>
<NavItem eventKey={4} href="#">Link</NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
);
}
});
我把navbrand也是在那里,展示如何用一个特定的值.bind单击处理(即0表示中性 - 没有突出显示)。
+0
谢谢你的回答,但我尝试添加活动到NavItem没有任何改变,howerver,当我添加禁用到NavItem它改变了 – May
你有没有想过这个问题? – anthonypliu