【问题标题】:Delete the user from the List : Ant Design从列表中删除用户:Ant Design
【发布时间】:2020-04-13 19:39:14
【问题描述】:

谁能帮我删除用户列表的数据 代码在https://codesandbox.io/s/r4try下方可用 请告诉我如何从用户列表中删除特定用户。请在用户上使用删除按钮

【问题讨论】:

    标签: reactjs antd


    【解决方案1】:

    解决办法

    Codesandbox Demo

    https://codesandbox.io/s/control-between-forms-ant-design-demo-99sus?file=/index.js
    
    
    <Form.Item
         label="User List"
                shouldUpdate={(prevValues, curValues) => prevValues.users !== curValues.users}
              >
                {({ getFieldValue, setFieldsValue }) => {
                  const users = getFieldValue('users') || [];
                  return users.length ? (
                    <ul>
                      {users.map((user, index) => (
                        <li key={index} className="user">
                          <Avatar icon={<UserOutlined />} />
                          {user.name} - {user.age}
                          <CloseOutlined onClick={() =>{
                            const updatedUsers = delete users[index];
                            setFieldsValue({users: updatedUsers})
                          }} style={{ paddingLeft: 15 }}/>
                        </li>
                      ))}
                    </ul>
                  ) : (
                    <Typography.Text className="ant-form-text" type="secondary">
                      ( <SmileOutlined /> No user yet. )
                    </Typography.Text>
                  );
                }}
              </Form.Item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-23
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      相关资源
      最近更新 更多