gpt4 book ai didi

javascript - jQuery UI 使用多个 JSON 源自动完成多个输入控件

转载 作者:行者123 更新时间:2023-11-30 10:49:23 26 4
gpt4 key购买 nike

我有这段代码在工作,来自 this example :

var url = function(req, res){
$.ajax({
url: "getdata",
dataType: "json",
data: {
term: req.term,
},
success: function(data){
res($.map(data.students, function(item){
return{
label: item.cardId + "|" + item.firstName + " " + item.lastName,
value: item.cardId
}}))
}
});
};


$("#autocomplete").autocomplete({
source: url
});
$("#autocomplete2").autocomplete({
source: url
});

和输入元素:

<input path="students" id="autocomplete" style="z-index: 100; position: relative" title="type &quot;a&quot;" autofocus="autofocus" />
<input path="items" id="autocomplete2" style="z-index: 100; position: relative" title="type &quot;a&quot;" />


两个输入现在都有相同的下拉列表。

问题:
如何更改 url 函数以适应 studentsitems?或者应该只为每种类型的输入复制函数?

最佳答案

在您的 url 函数中,this.element 将为您提供触发自动完成的元素。您可以使用 this.element.attr("id") 或其他一些方法来修改 JSONP url。

Demo herecode here

关于javascript - jQuery UI 使用多个 JSON 源自动完成多个输入控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6385937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com