{ let invoiceList = [...this.st-6ren">
gpt4 book ai didi

react-native - react native 。筛选FlatList- "index=10 count 0"错误

转载 作者:行者123 更新时间:2023-12-02 04:22:29 26 4
gpt4 key购买 nike

我的任务是过滤一些数组并将其设置为FlatList。

我的过滤器功能是:

updateInvoiceList = (text) => {
let invoiceList = [...this.state.baseInvoiceList];
invoiceList = invoiceList.filter(el => {
return el.name.toLowerCase().includes(text.toLowerCase())
});
this.setState({invoiceList})
}

过滤后,我将state.invoiceList提供给FlatList,并且一切正常。但是,当我设置数组中不存在的某个符号(例如“!”)时,该函数将清除该数组,并且它仍然可以正常运行。当我删除符号“!”时,出现以下错误屏幕:
 index=10 count=0
addInArray
ViewGroup.java:5235
addViewInner
ViewGroup.java:5128
addView
ViewGroup.java:4935
addView
ReactViewGroup.java:452
addView
ViewGroup.java:4875
addView
ReactViewManager.java:269
addView
ReactViewManager.java:36
manageChildren
NativeViewHierarchyManager.java:346
execute
UIViewOperationQueue.java:227
run
UIViewOperationQueue.java:917
flushPendingBatches
UIViewOperationQueue.java:1025
access$2600
UIViewOperationQueue.java:46
doFrameGuarded
UIViewOperationQueue.java:1085
doFrame
GuardedFrameCallback.java:29
doFrame
ReactChoreographer.java:166
doFrame
ChoreographerCompat.java:84
run
Choreographer.java:964
doCallbacks
Choreographer.java:790
doFrame
Choreographer.java:721
run
Choreographer.java:951
handleCallback
Handler.java:883
dispatchMessage
Handler.java:100
loop
Looper.java:214
main
ActivityThread.java:7356
invoke
Method.java
run
RuntimeInit.java:492
main
ZygoteInit.java:930

我做错了什么?

最佳答案

我的代码完全相同,位于Flatlist内,仅在Android上显示。我设法解决如下问题:

我的FlatList有

stickyHeaderIndices={this.state.items[1]}

但显然,列表在初始化之前就已加载了stickyHeader。从这里开始,解决方案仅在于处理尚未初始化该项目的情况。
stickyHeaderIndices={this.state.items.length > 0 ? [1] : [0]}

希望这可以帮助!解决方案非常简单。调试它可能是一个真正的痛苦,瞧!

关于react-native - react native 。筛选FlatList- "index=10 count 0"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58584676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com