jQuery UI自動完成的JSON格式

[英]JSON format for jQuery UI Autocomplete


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!

jQuery UI Autocomplete的文檔聲明source屬性可以設置為以JSON格式返回建議項的URL。但是,它沒有詳細說明這個JSON結果的結構應該是什么樣子。有人可以發一個例子嗎?謝謝!

6 个解决方案

#1


5  

This is a JSON Format

這是一種JSON格式

{source: ["Milan", "Turin", "Venice", "Florence", "Rome"] }

or another source

或其他來源

{source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]}

#2


14  

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

我發現.autocomplete正在尋找jquery UI 1.8這種格式

#3


1  

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.

我調用Java Spring控制器,它只返回下面的信息(采用JSOn格式)。我用JSTL構建它。但我不知道你使用什么樣的后端。但在所有語言中,您可以簡單地輸出一些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/

我不喜歡自動完成。也許你在flexbox中找到了一個更好的解決方案:http://flexbox.codeplex.com/

#4


1  

Did you look at the examples here? http://jqueryui.com/demos/autocomplete/#remote

你看過這里的例子了嗎? http://jqueryui.com/demos/autocomplete/#remote

#5


1  

Here is a real-world example, but it uses a JSONP remote datasource: http://www.highpoint.edu/admissions/contact.cfm

這是一個真實的例子,但它使用了一個JSONP遠程數據源:http://www.highpoint.edu/admissions/contact.cfm

The High School field uses autocomplete (make sure you Choose 'Freshman' for type of admission b/c otherwise the high school field will be hidden). Also, changing country/state selection will alter the autocomplete source somewhat, which might add some confusion.

高中字段使用自動完成(確保您選擇'新生'作為入學類型b / c否則高中字段將被隱藏)。此外,更改國家/州選擇將稍微改變自動完成源,這可能會增加一些混亂。

Also, that URL is just a wrapper for an iframe with the real form, which I cannot post a link to b/c new users can only post one URL in a comment.

此外,該URL只是具有真實表單的iframe的包裝器,我無法發布到b / c的鏈接新用戶只能在評論中發布一個URL。

#6


1  

using firebug we can see this format for json

使用firebug,我們可以看到json的這種格式

[{"id":"Podiceps nigricollis","label":"Black-necked Grebe","value":"Black-necked Grebe"}]

I used json_encode

我用了json_encode

$a[$x] = array("id" => $row["id"],"label"=>$row["label"],"value"=>$row["value"]);
}
//echo JSON to page
    $response =  json_encode($a);
echo $response;

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/11/16/313e982c81ca10f56ae99f2f3c6d52ec.html



 
  © 2014-2022 ITdaan.com 联系我们: