简体   繁体   English

过滤器 function 错误:: 未捕获错误:对象作为 React 子级无效....改用数组

[英]filter function error :: Uncaught Error: Objects are not valid as a React child .... use an array instead

Trying to display results after applying filter function.I need to compare with searchValue.but it gives Error在应用过滤器 function 后尝试显示结果。我需要与 searchValue 进行比较。但它给出了错误

{noteList.filter((obj,index) => <Card 
                noteObj={obj.Name.toLowerCase().includes(searchValue)} 
                index={index} 
                deleteNote={deleteNote}
                updateNoteArray={updateNoteArray}
             />)
} 

You need to first filter out the options from noteList array according to your condition and then apply a map over it.您需要首先根据您的条件从noteList数组中过滤掉选项,然后在其上应用map

{
noteList.filter((obj) => obj.Name.toLowerCase().includes(searchValue))
        .map((item,index) => <Card 
                noteObj={item} 
                index={index} 
                deleteNote={deleteNote}
                updateNoteArray={updateNoteArray}
             />
 )
}

noteList.filter((obj)=>obj.Name.toLowerCase().includes(searchValue)) This will return a new array which contains all the names which will includes searchValue . noteList.filter((obj)=>obj.Name.toLowerCase().includes(searchValue))这将返回一个新数组,其中包含所有将包含searchValue名称 Then you can use this resultant array to display your result然后你可以使用这个结果数组来显示你的结果

use map not filter使用mapfilter

{ noteList
.filter((obj, index)=>{ return obj.Name.toLowerCase().includes(searchValue)})
.map((obj,index) => <Card 
                noteObj={obj} 
                index={index} 
                deleteNote={deleteNote}
                updateNoteArray={updateNoteArray}
             />)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的错误:对象作为 React 子项无效,如果您打算呈现子项集合,请改用数组 - Uncaught Error: Objects are not valid as a React child , If you meant to render a collection of children, use an array instead Uncaught Error:Objects are not valid as a React child (found: object with keys.If you meant to render a collection of children, use an array instead 未捕获的错误:对象作为 React 子项无效(已找到:带键的对象。如果您打算呈现子项集合,请改用数组 - Uncaught Error:Objects are not valid as a React child (found: object with keys.If you meant to render a collection of children, use an array instead React:Uncaught Error:对象作为React子对象无效 - React: Uncaught Error: Objects are not valid as a React child 未捕获的错误:对象作为React子元素无效,但它是一个数组 - Uncaught Error: Objects are not valid as a React child but it's an array 未捕获的错误:对象作为 React 子项无效 - Uncaught error: Objects are not valid as a React child 未捕获的错误:对象作为React子对象无效 - Uncaught Error: Objects are not valid as a React child React错误:对象作为React子对象无效,如果要渲染子代集合,请改用数组 - React Error: Objects are not valid as a React child,If you meant to render a collection of children, use an array instead 对象作为 React 子级无效。 如果您打算渲染一组子项,请改用数组 - 错误 Solidity - React - Objects are not valid as a React child. If you meant to render a collection of children, use an array instead - Error Solidity - React react matrerial ui Error: Objects are not valid as a React child 如果您打算渲染一组子项,请改用数组 - react matrerial ui Error: Objects are not valid as a React child If you meant to render a collection of children, use an array instead 对象作为 React 子对象无效 - 请改用数组 - Objects are not valid as a React child - use array instead
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM