The documentation for jQuery UI Autocomplete states that the source
property can be set to a URL that returns the suggested items in JSON format. However, it doesn't elaborate further what the structure of this JSON result is supposed to look like. Could anyone post an example? Thanks!
In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.
Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })
(Entry 1 of 2) 1 : the act or an instance of asking for something. 2 : something asked for granted her request. 3 : the condition or fact of being requested available on request. 4 : the state of being sought after : demand.
Here we will make autocomplete textbox, in which make list pre-populated search result with image. This feature we will make by add custom html tag in jQuery UI autocomplete method by add _renderItem. Here we will use __renderItem method, by using this method we will add custom HTML code in autocomplete textbox.
Moved the answer here from my comment:
[{"label":"mylabel","value":"myvalue"},...]
I found it to be this format that .autocomplete is looking for for jquery UI 1.8
This is a JSON Format
{source: ["Milan", "Turin", "Venice", "Florence", "Rome"] }
or another source
{source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]}
using firebug we can see this format for json
[{"id":"Podiceps nigricollis","label":"Black-necked Grebe","value":"Black-necked Grebe"}]
I used json_encode
$a[$x] = array("id" => $row["id"],"label"=>$row["label"],"value"=>$row["value"]);
}
//echo JSON to page
$response = json_encode($a);
echo $response;
I do a call to a Java Spring controller that simply returns the information below (in JSOn format). I build it with JSTL. But I don't know what kind of backend you use. But in Allmost every language you can simple output some JSON.
Example:
{
"results": [{
"id": " Canned",
"name": " Canned"
}, {
"id": 64,
"name": "Added Sulphites"
},
{
"id": 3,
"name": "age"
}, {
"id": "age",
"name": "age"
}, {
"id": 59,
"name": "age group"
},
{
"id": "Allergen",
"name": "Allergen"
}, {
"id": 85,
"name": "Anchovies"
}
]
}
I dislike autocomplete. maybe you found a better solution in flexbox: http://flexbox.codeplex.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With