Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery自动完成:[对象]显示而不是值_Javascript_Jquery_Jquery Ui - Fatal编程技术网

Javascript jQuery自动完成:[对象]显示而不是值

Javascript jQuery自动完成:[对象]显示而不是值,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我使用jQueryUIAutoComplete从数据库中选择一个值。这一切都很好,只有一个例外。就我的一生而言,我无法在选择搜索值后,使用我正在写入搜索值的文本框来显示实际值 我已经读过很多次有这个问题的人,但是他们提出的解决方案并不适合我 小提琴在这里: 自动完成代码为: $("#student_search").autocomplete({ source: "functions/find_student.php", delay: 50, minLength: 3, selec

我使用jQueryUIAutoComplete从数据库中选择一个值。这一切都很好,只有一个例外。就我的一生而言,我无法在选择搜索值后,使用我正在写入搜索值的文本框来显示实际值

我已经读过很多次有这个问题的人,但是他们提出的解决方案并不适合我

小提琴在这里:

自动完成代码为:

$("#student_search").autocomplete({
  source: "functions/find_student.php",
  delay: 50,
  minLength: 3,
  select: function(event, ui) {
    var name_person = ui.item.label; // this works to give me the name of the person
    var house = ui.item.value.house;
    var id = ui.item.value.id;
    highlightStudent(name_person, id, house);
    $('#student_search').val(name);
  }
});
请注意,我已尝试:

用ui.label.value替换名称

正在尝试将close或change属性添加到autocomplete,其值为$'student_search'.valname

将$'student_search'.valname置于自动完成之外

我真的想不出还有什么地方可以放东西,所以我向你们大家求助

谢谢大家!! Alex

您是否尝试过event.preventDefault

select事件的默认行为是使用ui.item.value更新输入。此代码在事件处理程序之后运行

只需使用event.preventDefault或returnfalse阻止select和focusnot上的默认操作,即可正常工作

$("#student_search").autocomplete({
  source: "functions/find_student.php",
  delay: 50,
  minLength: 3,
  select: function(event, ui) {
    event.preventDefault();
    var name_person = ui.item.label; 
    var house = ui.item.value.house;
    var id = ui.item.value.id;
    highlightStudent(name_person, id, house);
    $('#student_search').val(name_person);
  }
});

这里有一个可行的解决方案:

你的小提琴不工作-你能重新创建一个产生错误的可行版本吗?这个名字来自哪里?你是说name_person吗?你没有为fiddle中的close属性定义任何内容,这就是为什么会出现错误的原因。删除属性或定义函数。您可以添加一个示例AJAX响应吗?这就是我得到的响应:{item:{label:Alexander Bunting,value:{id:6,house:s}}}}}从响应中收集值的所有内容都在工作,实际上只有一个框没有正确使用值。ui.item.label是绝对的。name是name_person,它们是相同的值-我上面截取的代码没有显示这一点,但它们具有相同的值和类型。close属性仍然是偶然存在的,从我尝试让它工作的时候开始。它仍然返回没有它的object对象。我在下拉列表中的项目上进行键控时仍然得到[object object]。有什么想法吗?