search multiple keys (alpine toolbox example) #484
Replies: 3 comments 9 replies
-
Hi @stoqe, thanks for the kind words! The first approach that comes to mind would be searching / filtering the array twice and then merging those 2 arrays together so that you have unique results. I've created a simple CodePen with an example: https://codepen.io/ryangjchandler/pen/pojZVbB The code is rather messy since I've thrown it together, but give it a go and let me know if you don't understand anything :) |
Beta Was this translation helpful? Give feedback.
-
You can write your condition inside a single filter directive return this.myForData.filter((item) => {
return item.employee_name.toLowerCase().includes(this.searchName.toLowerCase()) || item.employee_age == this.searchName
}); It's standard javascript at that point so you can combine them as you need. |
Beta Was this translation helpful? Give feedback.
-
If you wanted to go even beyond what @SimoTod and @ryangjchandler suggested, you can actually use a full text search engine implemented in JavaScript, there are a couple around, fuse.js and lunr.js come to mind (see https://www.npmjs.com/package/fuse.js or https://www.npmjs.com/package/lunr). This will allow you to create more complex match rules and weighted full-text search (eg. if I find the search in the title of a post, it'll be a closer match than if it just appears in the description or text). |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions