jQuery UI自动完成不填充下拉列表 [英] jQuery UI Autocomplete not populating dropdown
问题描述
试图让jquery自动完成返回并填充它的下拉列表.输入和调用看起来像这样:
Trying to get jquery AutoComplete to return and populate it's dropdown. The input and call looks like this:
<input id="user_login" name="user[login]" size="22" type="text" value="" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#user_login, #user_group_name').autocomplete({
source: '/users.js'
});
});
</script>
被调用的URL字符串是:
The URL string that gets called is:
http://localhost:3000/users.js?term=user
users.js的返回结果如下:
The return from users.js looks like this:
[{"id":1802,"login":"some.user"},{"id":3882,"login":"some.other_user"},{"id":2024,"login":"user"}]
自动完成功能似乎可以解释某些回报:它用三个LI填充自动完成功能UL,但它们都为空.如果我搜索其他内容,则会创建适当数量的空LI.我已经使用JSONLint验证了JSON返回.
The autocomplete seems to interpret some of the return: it populates the autocomplete UL with three LIs, but they are all empty. If I search for something else, the appropriate amount of empty LIs is created. I've verified the JSON return with JSONLint.
推荐答案
问题出在我的退货上.自动完成功能每学期只需要一个项目,就像这样:
The problem was with my return. Autocomplete wanted a single item per term, like so:
[{"login":"some.user"}]
这篇关于jQuery UI自动完成不填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!