我正在使用jQuery的自动完成插件来获得简单的搜索表单.我无法将我的JSON对象数据转换为数组以供自动完成使用.
我的代码:
var listOfOrderedByNames = getAutocompleteData();
$('#OrderedBy').autocomplete(listOfOrderedByNames);
function getAutocompleteData() {
var output;
$.getJSON('AJAX/GetOrderedByNames', function(data) {
$.each(data, function(index, optionData) {
output += optionData + "|";
});
});
return output;
}
Run Code Online (Sandbox Code Playgroud)
我返回的JSON数据如下所示:
["Jimmy","John", "Etc",null]
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它看起来像我从该getAutocompleteData函数返回的是一个空字符串,我不知道有什么问题.
请帮忙!
我正在使用jQuery自动完成文本框.我的代码和脚本工作正常,但现在我需要一个'可滚动的下拉列表(沿着X轴和Y轴)而不是一个简单的下拉列表.
用于促进自动完成下拉列表的脚本:
$(function () {
$("#TextBox").autocomplete({
source: "home/search",
dataType: 'json',
minLength: 1,
// max: 10,
// scroll:true
});
});
Run Code Online (Sandbox Code Playgroud) 如果有人可以帮助我在rails应用程序中实现自动完成功能,那将是非常有帮助的.我尝试了jquery auto complete plugin.I无法实现.
我的控制器:
def new
@testers = User.find_by_sql("select * from users where id in(select user_id from user_role_assignments where role_id in (select id from roles where name like 'Tester')) order by name").paginate(:page=>params[:page],:per_page=>30)
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @release }
end
end
Run Code Online (Sandbox Code Playgroud)
我想为@testers创建一个自动完成
查看代码:
= form.label :tester_tokens, "Testers"
= form.text_field :tester_tokens
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助,
拉姆亚.
对于一个网站,我将在不同的页面上有很多自动完成字段.
它们在所有页面上的工作方式完全相同,但它们不能调用相同的URL.
我想知道是否有可能提到<input>将成为自动填充字段的网址?目标是为许多html代码提供一个js代码
我尝试了一些东西,但它似乎不起作用:Html:
<input type="field" name="search" class="autocomplete" value="Search" url="smalltest/otherTest/..." />
Run Code Online (Sandbox Code Playgroud)
和JS
$(document).ready(function () {
$("input.autocomplete").autocomplete({
source: $(this).attr("url")
}); });
Run Code Online (Sandbox Code Playgroud)
我在jquery lib中遇到异常.
javascript jquery jquery-ui autocomplete jquery-autocomplete
我是jQuery和JSON的新手,花了好几个小时但仍然没有解决问题
来自服务器的JSON有效,通过jsonlit.com检查但它仍然显示所有数据(未过滤).
来自serverURI.asp的JSON
["A. ASRUNADI", "A. MURSYID", "A. RIFANI", "A.Z MAKMUR IS", "ABBAS", "ABDI IRWANTO"]
Run Code Online (Sandbox Code Playgroud)
我的jquery
$("#keyword").autocomplete({
source: function(request, response){
$.getJSON("serverURI.asp", function(data){
var source = data
response(source);
});
}
});
Run Code Online (Sandbox Code Playgroud)
但....当我把JSON作为var in jquery时它的作品...同时我已经在我的html元标记中使用了utf-8
$(function() {
var availableTags = ["A. ASRUNADI", "A. MURSYID", "A. RIFANI", "A.Z MAKMUR IS", "ABBAS", "ABDI IRWANTO"];
$("#keyword").autocomplete({
source: availableTags
});
});
Run Code Online (Sandbox Code Playgroud)
我的ASP(经典)生成JSON如下
dim strResultEMP
strResultEMP = "["
for strEmpCount = 0 to strTotalCountEmp
strEmpObj = split(strEmpSplit(strEmpCount), "$$$")
if strEmpCount < strTotalCountEmp then
strResultEMP = strResultEMP & …Run Code Online (Sandbox Code Playgroud) jquery jquery-ui asp-classic jquery-autocomplete jquery-ui-autocomplete
我正在使用 jQuery UI 自动完成。但是打字很慢。例如,当我在 Google 搜索框中键入时,建议会显示在框底部,而且速度非常快。谷歌的自动完成调用需要大约。80 毫秒(根据 Firebug 请求分析)。
我的服务在 80-100 毫秒的同一时间范围内提供建议,但 jQuery 自动完成的实现速度非常慢,以至于在我写完整个单词后,结果就会出现在框下。
有人有更好的自动完成解决方案,比如 Google 的速度,或者有什么方法可以优化 jQuery UI 自动完成?
我无法与带有casperjs的jquery自动完成输入框进行交互.我尝试了很多不同的方法,但是当弹出选项列表时,我似乎无法选择自动完成选项.
我的代码如下:
casper.thenEvaluate(function() {
$('#myInput').val('cars'); // fill in the text box
$('#myInput').blur(); // should trigger the autocomplete ajax call
$('.ui-autocomplete li.ui-menu-item:nth-of-type(1)').click(); // should click the first item in the list
});
// take a picture to make sure it worked
casper.then(function() {
this.captureSelector('pics/test1.png', '#theForm');
});
Run Code Online (Sandbox Code Playgroud)
这根本不起作用,即使看起来应该如此.通过玩弄它,我发现触发向下箭头按键几次触发自动完成显示,所以这是一个更接近工作的版本.这适用于浏览器,但由于某种原因不适用于casper.thenEvaluate块.
$('#myInput').val('cars'); // fill in the text box
var e = jQuery.Event("keydown");
e.which = 40; // press down arrow a few times, not sure why this works
$("#myInput").trigger(e);
$("#myInput").trigger(e);
$('.ui-autocomplete li.ui-menu-item:nth-of-type(1)').click();
Run Code Online (Sandbox Code Playgroud) jquery browser-automation browser-testing jquery-autocomplete casperjs
我目前正在使用这个插件:
https://github.com/devbridge/jQuery-Autocomplete
我要的是,当我从选定的选项名称的文本字段我可以得到的价值,并把它作为对参数的地址文本字段中的选项地址字段限制只在名称中该地址存在。
同样,当我从地址字段中选择一个选项时,姓名字段中的选项仅限于居住在该地址的人员的姓名。
这是我的代码:
$(document).ready(function(){
var name = '';
var add = '';
$('#name').change(function() {
name = $('#name').val();
});
$('#add').change(function() {
add = $('#add').val();
});
$('#name').devbridgeAutocomplete({
serviceUrl: 'search/name',
minChar: 2,
params: {add: add},
onSelect : function(suggestion) {
$('#name').val(suggestion.value);
}
});
$('#name').devbridgeAutocomplete({
serviceUrl: 'search/address',
minChar: 2,
params: {name: name},
onSelect : function(suggestion) {
$('#name').val(suggestion.value);
}
});
});
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不起作用,我做对了还是做错了?请帮忙!
有没有其他人遇到过这个问题或知道解决方案?
在文本字段中进行更改时,jQuery会调用Spring Controller.我的问题是这个查询如何发送@RequestParam到Controller方法controller/find?
如何Param在此通话中发送额外内容?
$(document).ready(function() {
$( "#id" ).autocomplete({
source: "${pageContext. request. contextPath}/controller/find.htm"
});
});
Run Code Online (Sandbox Code Playgroud)
这有效
@RequestMapping(value = "/find", method = RequestMethod.GET)
public @ResponseBody
List<String> findItem(@RequestParam("term") String id)
Run Code Online (Sandbox Code Playgroud)
但需要类似的东西
@RequestMapping(value = "/find", method = RequestMethod.GET)
public @ResponseBody
List<String> findItem(@RequestParam("term") String id, Additional param here ??)
Run Code Online (Sandbox Code Playgroud) 在自动完成框中的键输入,我将以JSON格式从MVC控制器返回Key,Value对.
public ActionResult UserNameAutoComplete(string term)
{
DBEntities db = new DBEntities();
...codes to get data from database
jsonString += jSearializer.Serialize(userList);
return Json(jsonString, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
重新编写的Json字符串是[{"UserId":"1","UserName":"admin"},{"UserId":"3","UserName":"newtonsheikh"}]
在视图中我得到了这个

jquery是
$("#Username").autocomplete({
source: '@Url.Action("UserNameAutoComplete")'
});
Run Code Online (Sandbox Code Playgroud)
我的问题是如何解析这个返回的json?预期的产出是

jquery ×10
autocomplete ×4
jquery-ui ×3
json ×2
ajax ×1
asp-classic ×1
asp.net-mvc ×1
casperjs ×1
javascript ×1
spring-mvc ×1
textfield ×1