【发布时间】:2021-02-27 06:19:58
【问题描述】:
当我单击添加朋友按钮时,我面临一个问题,每个按钮都会更改为请求我如何才能将其特别设置为仅我单击的一个用户我尝试了一些事情但它不起作用它正在选择所有其他用户。我使用了handleproductselect 功能,但它不起作用我给了他们单独的ID,但它仍然不起作用
class SearchModal extends Component {
constructor(props){
super(props);
this.state = {
Input:"Add Friend",
backgroundColor: 'white',
active_id: null,
}
}
async handleProductSelect(elementid){
const id = elementid;
const { backgroundColor } = this.state;
let newBackgroundColour = backgroundColor === 'white' ? 'yellow' : 'white';
this.setState({
Input : "Requested",
backgroundColor: newBackgroundColour,
active_id: id
})
console.log(id)
}
render() {
const {currentUser} = this.props;
return (
<div>
<Modal show={this.state.show} onHide={this.handleClose}
>
<Modal.Header closeButton>
<Modal.Title>
<input
type="text"
placeholder="Search.."
value={search}
onChange={this.onTextboxChangeSearch}
></input>
</Modal.Title>
</Modal.Header>
<Modal.Body>
<h3>Users</h3>
<div>
<ul className="collection">
{userdetails.map((element) => {
if(currentUser.user.username !== element.username){
return(
<div key={element._id}>
<li>{element.username}{' '}<input
type="button"
id={element._id}
onClick={this.handleProductSelect.bind(this,element._id )}
value={this.state.Input}
style = {{backgroundColor: ( element._id === this.state.active_id ? 'yellow' : this.state.backgroundColor)}}></input></li>
</div>
);
}else{
return(
<div key={element._id}>
<li>{element.username}</li>
</div>
);
}
})}
</ul>
</div>
</Modal.Body>
</Modal>
</div>
)
}
}
【问题讨论】:
标签: reactjs select button compiler-errors mern