嗨,我制作了簡單的 antd 串列,用戶可以在其中添加、洗掉編輯串列。但問題是,當我添加時,編輯串列非常有用。但是當我從串列中洗掉專案時,antd 總是從串列中洗掉最后一項。雖然我可以洗掉任何專案。
const [employeeList, setEmployeeList] = useState([])
<List
dataSource={employeeList}
renderItem={(item, index) => (
<List.Item id='listItem' >
<Input
id='listItem-input'
defaultValue={item.name}
onChange={(i) => {
employeeList[index].name = i.target.value
setEmployeeList(answerList)
}}
/>
<span className='removeItem'
onClick={() => {
let newList = setEmployeeList
newList[index] = undefined
setEmployeeList(newList.filter(e => e))
}}
>
<CloseOutlined/>
</span>
</List.Item>
)}
/>
我簽入狀態的控制臺專案被洗掉,盡管它仍然保留在 item.list
uj5u.com熱心網友回復:
首先,我建議使用splice()洗掉專案
所以而不是onClick(洗掉)中的這3行
employeeList.splice(index,1)
編輯:
使用您的方法,您可能想要: let newList = employeeList
newList[index] = undefined
uj5u.com熱心網友回復:
原來我不得不使用鑰匙。List.Item 沒有注冊沒有鍵的更改,只是洗掉了最后一個專案,任何更改。
<List.Item id='listItem' key={item.answer} >
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/495494.html
標籤:javascript 反应 列表 列表显示 蚂蚁
