且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ListView 在数据源更新时删除错误的行

更新时间:2023-02-06 23:09:42

我不确定这是否是正确的答案,但它对我有用,直到我能找到更好的解释/更好的答案.

I'm not sure if this is the proper answer, but it's worked for me until I can find a better explanation/better answer.

我最近遇到了同样的问题,我正在与之交谈的其他人也是如此.他们通过向 ListView 添加一个关键属性来修复它.显然,您需要向 ListView 添加键,因为表行是超级动态的,似乎每行上没有键会导致 ListView 错误地选择要删除的行.

I recently had this same question, as did someone else I was talking to. They fixed it by adding a key property to the ListView. Apparently, you need to add key to ListView because the table rows are super dynamic, and it seems like not having the key on each row was causing ListView to incorrectly choose what row to get deleted.

<ListView
  key={putSomethingUniqueInHere}
  dataSource={this.state.dataSource}
  renderRow={this.renderRow.bind(this)}
/>