How to select item(s) out of a FlatList?

为君一笑 提交于 2019-12-04 16:37:04

What about this:

Every item rendered would have an onLongPress, and an isPicked property.

Initially, and in renderItem(), you would implement an if statement that either renders checked square or empty square every time an item executes executes; To indicate if the item is selected or not (based on isPicked).

onLongPress invokes isPicked and rerenders everything (to toggle the square). So if isPicked is true it becomes false, and if false becomes true. You can achieve that by simply doing this: this.item.isPicked = !this.item.isPicked

Finally on Submit, filter all your initial items (data) by the isPicked === true and hurrah, you will end up with the items that were selected !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!