【发布时间】:2022-09-23 17:32:53
【问题描述】:
如何从对象数组中搜索任何内容?
let cars = [
{
\"color\": \"purple\",
\"type\": \"minivan\",
\"registration\": new Date(\'2017-01-03\'),
\"capacity\": 7
},
{
\"color\": \"red\",
\"type\": \"station wagon\",
\"registration\": new Date(\'2018-03-03\'),
\"capacity\": 5
},
]
return (
<>
<input type=\"text\" onChnage={(e) =>setSearchInput(e.target.value)}
{
cars?.filter(x => Object.values(x).includes(searchInput.toLowerCase())).map((d) =>{
console.log(d) // nothing is consoled from here tu
//show the data here but nothing is showing here
})
}
</>
)
没有错误,但数据没有显示任何内容,这里有什么问题?
-
Object.values(x).includes(searchInput.toLowerCase())将返回布尔值。因此地图不会被执行 -
@SrushtiShah那么我需要改变什么才能得到我想要的?
-
请发布您的整个代码,以便我可以帮助您
-
@死人...\“没有错误,但数据没有显示任何内容,这里有什么问题?\”......也许是一个错字? ...
onChnage应该是onChange。
标签: javascript reactjs arrays filter jsx