0
我有一個數組,我想從用戶的輸入中添加一個新名稱。在我的部分,我有:當使用onClick時,反應輸入數值不工作
<div>
<h4>Add A Player</h4>
<input
type="text"
placeholder="Enter a new name"
value={this.state.newPlayerName}
/>
<button onClick={this.handleAddPlayer}>
Press to Add Player
</button>
</div>
其中除名稱使用此功能的工作原理:
handleAddPlayer = e => {
const players = this.state.players.slice(0);
players.push({
name: '',
id: getRandomInt(20, 55)
});
this.setState({
players: players,
newPlayerName: e.target.value
});
};
我想,當用戶輸入一個名稱,並將其提交獲取,它在更新函數更新數組(如果這是有道理的,道歉,因爲這對我來說仍然很新)。
在我的國家,我有:
this.state = {
id: players.id,
totalScore: 0,
countInfo: [],
evilName: '',
color: '#6E68C5',
scoreColor: '#74D8FF',
fontAwe: 'score-icon',
incrementcolor: '',
scoreNameColor: 'white',
glow: '',
buttonStyle: 'count-button-start',
newPlayerName: '',
players
};
我不知道如何讓輸入要通過域名(或字符串)陣列,任何人都可以幫忙嗎?