在vue.js中使用空白空间搜索问题
我在vue.js中的输入搜索字段有问题。
在我的数据中,我有嵌套阵列,它们具有标题。当我搜索标题并击中空间时,什么也不会出现。并应使用空格搜索标题。例如,我有一个标题为“商店中的铅笔”,当我在输入中写“铅笔”时,它确实与所有其他信息一起出现。当我写“铅笔”时,什么都没有出现。另外,在某些标题中,我无法到达空白空间,只有在写“笔”时才会出现结果。这是我的代码,我尝试了修剪和分裂,但它没有用。 非常感谢!
computed: {
getfiltered() {
const search = this.search;
return (
this.categories.filter(category =>
category.title.includes(search.toLowerCase()) ||
category.infos.some(info => info.name.includes(search)
)
)
)
},
这是输入字段
<input type="text" v-model="search" placeholder="Search" />
<div v-for="(category, categoryIndex) in getfiltered" :key="categoryIndex">
<h2>{{category.title}}</h2>
</div>
和数据
export default {
data: () => ({
search: '',
categories: [
{
title: 'Pencils in store',
infos: [{name:'Bic'},
{name:'Crayola'}]
}, //...and so on
I have a problem with input search field in vue.js.
In my data I have nested arrays, which have titles. When I search the titles and hit space, nothing appears. And titles should be searched with spaces. For example I have a title "Pencils in store" and when I write "Pencils" in input, it does appear with all other information. When I write "Pencils in" nothing appears. Also, in some of the titles I can't reach to the blank space, results appears only while I write "Pen". Here is my code, I have tried with trim and split, but it did not work.
Very thanks in advance!
computed: {
getfiltered() {
const search = this.search;
return (
this.categories.filter(category =>
category.title.includes(search.toLowerCase()) ||
category.infos.some(info => info.name.includes(search)
)
)
)
},
Here is the input field
<input type="text" v-model="search" placeholder="Search" />
<div v-for="(category, categoryIndex) in getfiltered" :key="categoryIndex">
<h2>{{category.title}}</h2>
</div>
And the data
export default {
data: () => ({
search: '',
categories: [
{
title: 'Pencils in store',
infos: [{name:'Bic'},
{name:'Crayola'}]
}, //...and so on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@estus烧瓶评论的方式解决了问题。
category.title.tolowercase()。包括(search.tolowercase())
The problem is solved in a way that @Estus Flask commented.
сategory.title.toLowerCase().includes(search.toLowerCase())