jQuery自动完成JSON响应 [英] jQuery Autocomplete JSON response

查看:67
本文介绍了jQuery自动完成JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQueryUI自动完成插件,但无法使其正常工作.

I am trying to use the jQueryUI autocomplete plugin but I am unable to make it work.

我在后端使用Spring MVC,并通过遵循以下我从网上获得的帖子.

I am using Spring MVC at the backend and I am returning JSON response by following this this post that I got from the net.

我的问题是,自动完成插件期望JSON响应的方式似乎存在一些问题.我检查了萤火虫,它显示在JSON响应下方.

My problem is, there seem to be some problem in the way the autocomplete plugin expects the JSON response. I checked on my firebug and it is displaying below JSON response.

{"data":["TEST-01","TEST-02","TEST-03"]}

没有引发任何错误,但是自动完成功能没有任何提示.

No error is being thrown, but the autocomplete is not suggesting anything.

推荐答案

为什么不咨询官方jquery -ui文档有关预期的响应格式?

Why don't you consult official jquery-ui documentation about expected response format?

简而言之,有效的响应可能看起来像这样

In short, valid response could look like this

[{'label': 'TEST-01'}, {'label': 'TEST-02'}, {'label': 'TEST-03'}]

更多来自文档
数据可以是一个简单的字符串数组,也可以包含数组中每个项目的对象,这些对象可以带有label或value属性,或者同时具有二者.标签属性显示在建议菜单中.用户从菜单中选择某项后,该值将插入到输入元素中.如果仅指定一个属性,则将同时使用这两个属性.如果仅提供value-properties,则该值还将用作标签.

More from the docs
data can be a simple Array of Strings, or it contains Objects for each item in the array, with either a label or value property or both. The label property is displayed in the suggestion menu. The value will be inserted into the input element after the user selected something from the menu. If just one property is specified, it will be used for both, eg. if you provide only value-properties, the value will also be used as the label.

这篇关于jQuery自动完成JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆