Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling non-array response from endpoint? #17

Open
lentzi opened this issue Apr 23, 2018 · 5 comments
Open

Handling non-array response from endpoint? #17

lentzi opened this issue Apr 23, 2018 · 5 comments

Comments

@lentzi
Copy link

lentzi commented Apr 23, 2018

Does the component only work if the request returns an array? My endpoint returns an object in the form of { statusCode: "200", entity: Array[] }. Is there a way to tell the component to handle response.entity instead of response, because currently I'm getting an error when the component tries calling response.map() when response is actually an object. (I've looked through all your public resources, including the demo)

@orizens
Copy link
Owner

orizens commented May 29, 2018

hi @lentzi
r u referring to the jsonp way of this component?

danish-jamil added a commit to danish-jamil/ngx-typeahead that referenced this issue Aug 13, 2018
…f results is an object and associated with a key

Added @input() taEmptyOnSelect to empty the field on result selection
danish-jamil added a commit to danish-jamil/ngx-typeahead that referenced this issue Aug 13, 2018
@i-n-g-m-a-r
Copy link

i-n-g-m-a-r commented Dec 13, 2018

Is there a current status on this?
It seems that the library is specifically designed to handle suggestions from Google.
Things like this:

function toJsonpSingleResult(response) {
    return response[1];
}

Where does the [1] part come from?
Maybe from this - the actual suggestions by Google, inside [1] :

ng_jsonp_callback_0 && ng_jsonp_callback_0(
	[
		"berlin",
		[
			["berlin",0,[131]], ["berlin take my breath away",0,[131]], 
			["berlin marathon 2018",0], ["berlin wall",0,[131]],
			["berlin techno",0,[131]], ["berlin stirbt",0,[131]],
			["berlin calling",0], ["berlin wall coming down",0,[131]],
			["berlin station trailer",0,[131]], ["berlin wall documentary",0,[131]]
		],
		{"k":1,"q":"onZ0QTsumy3nJdCP2FQEiahNa08"}
	]
)

Is the library intended to be extensible?

@orizens
Copy link
Owner

orizens commented Dec 13, 2018

@i-n-g-m-a-r i'm thinking about a proper handler for this

@i-n-g-m-a-r
Copy link

@orizens maybe something like this:

Client component:

	[taResultsDecorator]="resultsDecorator"

...

    resultsDecorator(results: any) : any[] {
        return ["foo", "bar", "qux", "baz"];
    }

NgxTypeAheadComponent:

	@Input()
	taResultsDecorator = (results: any) : any[] => results;

...

	assignResults(results: any[]) {
		const labelForDisplay = this.taListItemLabel;
		this.resultsAsItems = this.taResultsDecorator(results); // decorate results
		this.results = this.resultsAsItems.map( // use decorated results
			(item: string | any) => (labelForDisplay ? item[labelForDisplay] : item)
		);
		this.suggestionIndex = NO_INDEX;
		if (!results || !results.length) {
			this.activeResult = this.searchQuery;
		}
	}

@kooison
Copy link

kooison commented May 8, 2020

It’s a great idea, my application query result from Solr and it can only return in object form. Any plan to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants