我从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 "a"" autofocus="autofocus" />
<input path="items" id="autocomplete2" style="z-index: 100; position: relative" title="type "a"" />
两个输入现在都有相同的下拉列表。
的问题:
如何更改网址功能以适应学生和项目?或者只应复制每种输入类型的函数?