朋友们,我为自动完成创建了一个新的 js 文件。除了一行“receiveingAutocompleteData = data.autcompleteData;”外,一切正常 右侧的值未分配给左侧。
var ArrayAutocomplete = [];
var receivingAutocompleteData ;
function AutoComplete1(txtBoxName, idField, fieldName) {
debugger;
ArrayAutocomplete = [];
var selectedReqType = $("#" + txtBoxName).val();
$("#" + txtBoxName).unautocomplete();
$("#" + txtBoxName).val("");
$("#" + txtBoxName).val("Loading...........");
$("#" + txtBoxName).attr("disabled", true);
// var rea= "<%= Url.RouteUrl(new { controller = "Request", action = "AutoSelectionDataForRequestType"}) %>";
var rea = getURL(fieldName);
$.post(rea, {}, function (data) {
debugger;
receivingAutocompleteData = data.autcompleteData;
jQuery.each(receivingAutocompleteData, function (i, val) {
if (val.Name != "")
ArrayAutocomplete.push(val.Name + '|' + val.ID);
});
ArrayAutocomplete.sort();
// alert(ArrayAutocomplete.length);
// alert(ArrayAutocomplete);
$("#" + txtBoxName).autocomplete(ArrayAutocomplete, {
minChars: 0,
max: ArrayAutocomplete.length,
autoFill: true,
mustMatch: true,
matchContains: false,
multipleSeparator: ',-',
scrollHeight: 220,
formatItem: function (data, index, max) {
return data[0];
},
formatMatch: function (data, index, max) {
return data[0];
}, formatResult: function (data, index, max) {
return data[0];
}
}).result(function (event, data, formatted) {
if (data)
$("#" + idField).val(data[1]);
else
$("#" + idField).val('-1');
});
$("#" + txtBoxName).val("");
$("#" + txtBoxName).attr("disabled", false);
$("#" + txtBoxName).Watermark("--Select--");
if (selectedReqType != '')
$("#" + txtBoxName).val(selectedReqType);
});
}