zsharp
zsharp

Reputation: 13756

JQuery AutoComplete results format?

I have a string of values separated by a space that I return to the Jquery call, but it does not separate the words into rows. Should the data be returned as a string or a list or something else?

Upvotes: 2

Views: 6107

Answers (3)

Morph
Morph

Reputation: 1719

There is another autocomplete plugin that wants to have a string separated by the '|' character like this:

item 1 | item 2 |

You might want to check the docs of the one you're using !

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532435

By default it wants the results separated by newlines. If you supply a list of values separated by spaces you'll want to provide a parse function that will take the returned data and turn it into an array. The same is true if you supply a list of values instead.

Here's a sample from a project I'm working on that returns a list of strings via JSON from an MVC action.

$('#eventName').autocomplete( '<%= Url.Action("SearchEvent", "Donor" ) %>', {
    dataType: "json",
    formatItem: function(data,i,max,value,term){
       return value;
    },
    parse: function(data){
        var array = new Array();
        for(var i=0;i<data.length;i++)
        {
            array[array.length] = { data: data[i], value: data[i], result: data[i] };
        }
        return array;
   }
});

Upvotes: 5

nickohrn
nickohrn

Reputation: 2248

If you're using the plugin located here, then I think you return results in JSON format. Here's how to do it with ASP.Net MVV.

Upvotes: 4

Related Questions