0
我刚刚开始学习React并试图在联系人列表中实现切换效果,当您单击它时应显示有关联系人的其他信息。React JS切换显示有关联系人的其他信息
当前的代码如下:
var CONTACTS = [
{
id: 1,
name: 'Darth Vader',
phoneNumber: '+250966666666',
image: 'img/darth.gif',
email: '[email protected]',
address: 'Death Star'
}, {
id: 2,
name: 'Princess Leia',
phoneNumber: '+250966344466',
image: 'img/leia.gif',
email: '[email protected]',
address: 'Naboo'
}
];
var Contact = React.createClass({
getInitialState : function() {
return {
isOpened : false
};
},
toggleState : function() {
this.setState({
isOpened: !this.state.isOpened
});
},
render: function() {
return (
<li className="contact" onClick={this.toggleState}>
<img className="contact-image" src={this.props.image} width="60px" height="60px" />
<div className="contact-info">
<div className="contact-name"> {this.props.name} </div>
<div className="contact-number"> {this.props.phoneNumber} </div>
<div> {this.state.isOpened} </div>
</div>
</li>
);
}
});
如何我设置isOpened等于联系地址和电子邮件,以显示其切换被触发时? 谢谢!