[英]Change innerText of Button ReactJS
在選中所有checkboxes
后,我想將Check All
Button 內部文本更改為Uncheck All
。 這是我的代碼。 有什么建議么?
checkAllCheckBox = () => {
let {todos} = this.state
let newArray = [...todos]
if (newArray.length !==0) {
newArray.forEach(item => {
if (item.checked === true) {
item.checked = false
} else {
item.checked = true
}
this.setState({todos: newArray})
})
console.log('----todos', todos)
}
}
render() {
const {itemsPerPage, currentPage, todos} = this.state;
console.log('--------todos', todos);
const end = currentPage * itemsPerPage
const start = end - itemsPerPage
const currentItems = todos.slice(start, end);
return <div className={"App"}>
<div className="App-header">
<h2>Welcome to To-Do List App</h2>
</div>
<input ref={this.inpRef} onKeyPress={this.handleKeyPress} name={''} type='text'/>
<button onClick={() => this.addItem()} className={'btn btn-primary'}>Add</button>
<button onClick={() => this.checkAllCheckBox()}
className={'btn btn-primary'}>Check All</button>
<ul>
{
currentItems.map(todoItem => {
return <ListItem
key={todoItem._id}
todoItem={todoItem}
deleteItem={this.deleteItem}
editItem={this.editItem}
submitEdit={this.submitEdit}
deleteData = {this.deleteData}
/>
})
}
<div>
{this.renderPagination()}
</div>
</ul>
</div>
};
}
export default App;
將Check All
替換為{this.state.todos.every(todo => todo.checked)? "Uncheck All": "Check All"}
{this.state.todos.every(todo => todo.checked)? "Uncheck All": "Check All"}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.