小编Dav*_*omo的帖子

从 React 中的数组中删除项目

我的 removeItem 函数有问题(它应该删除当前<li>嵌套的按钮,以及 this.state.list 上的数组中的项目),目前没有代码,因为我尝试了很多东西,但没有任何效果,所以我最终console.logs看的是什么发生了所以我删除了它

import React, { Component } from 'react';
import './Todo.css';

class Todo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            text: ''
        }
        this.textChange = this.textChange.bind(this);
        this.addToList = this.addToList.bind(this);
        this.removeItem = this.removeItem.bind(this);
    }

    textChange(e) {
        this.setState({
            text: e.target.value
        })
    }

    addToList() {
        this.setState(prevState => ({
            list: prevState.list.concat(this.state.text),
            text: ''
        }))
    }

    removeItem(e) { ?
        ? ? ? ? ? ? ?
    }

    render() {
        return(
          <div>
            <h1>My Todo List</h1> …
Run Code Online (Sandbox Code Playgroud)

reactjs

3
推荐指数
2
解决办法
8万
查看次数

标签 统计

reactjs ×1