朋友我已經爲自動完成創建了一個新的js文件。一切工作正常,除了一行「receivingAutocompleteData = data.autcompleteData;」 右側的值未分配給左側。作業在外部js文件中不起作用
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);
});
}
無法在此處說出最新錯誤,因爲您正在處理髮布請求的結果。你確定data.autcompleteData實際上包含一個值嗎?你有錯字嗎?它應該是autoCompleteData? –
我已經調試了應用程序並在「data.autcompleteData」變量中找到了值,但該值未分配給左操作數。 – user1194147