我知道我可以遍历数组并只更改value toLowerCase()。
我很好奇是否有一个reactjs或es6方法可以检查值是否在数组中。
在addTodo函数上。您可以看到我使用了include,但是此方法区分大小写。
这就是我所拥有的
class Todo extends React.Component {
render() {
return (
<div className="todo">
<input type="checkbox" />
<p>{this.props.children}</p>
</div>
);
}
}
class App extends React.Component {
constructor(props) {
super(props);
this.todos = [
'Get Up from bed',
'Eat Breakfast'
];
}
eachTodo(task, i) {
return (
<Todo key={i} index={i}>{task}</Todo>
)
}
addToDo() {
let task_title = this.refs.newTodo.value;
if(task_title !== '') {
let arr = this.todos;
var arr_tlc = this.todos.map((value) => {
return value.toLowerCase(); …Run Code Online (Sandbox Code Playgroud)