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 联系我们: