sickdyd / react-search-autocomplete

A search box that filters the provided array of objects
https://sickdyd.github.io/react-search-autocomplete
MIT License
218 stars 82 forks source link

Function formatResult only return one field, how to get full data from this #30

Closed taixe closed 2 years ago

taixe commented 2 years ago

How to I can get full objet data in this function. it only return item is name. I want to get full data item = {name:"", image:"abc", etc...} const formatResult = (item) => { return item; // return (<p dangerouslySetInnerHTML={{__html: ''+item+''}}>

); //To format result as html }

sickdyd commented 2 years ago

@taixe For that you need to use onSearch and not formatResult. onSearch will return the full object, formatResult is used only to format the string in the results list.

taixe commented 2 years ago

hi @sickdyd . But I want to use formatResult to format data cell, show name, price, image ...

sickdyd commented 2 years ago

@taixe This can't be done now, but it seems easy to change. You can fork the repo and change this:

{formatResult(result[resultStringKeyName])}

to:

{formatResult(result)}

In Results.js, and you should get the full result in the callback.

taixe commented 2 years ago

yea, thank @sickdyd

glowdex commented 2 years ago

hi! I would like to do this too. I can fork and change as discussed above but I was wondering if it's possible to add it as an option for the function in the official package (whether you want the full results)?