0

朋友们,我为自动完成创建了一个新的 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);
   });

}

4

2 回答 2

0

jQuery 使用 content-type 标头来确定返回数据的类型。由于大多数服务器不发送,application/json因此您必须指定“json”作为数据类型(第 4 个参数$.post

你也可能有错字

我认为应该是

data.autocompleteData

代替

data.autcompleteData
于 2012-07-03T06:51:29.970 回答
0

是什么data

可能你刚刚打错了receivingAutocompleteData = data.autcompleteData;; 正确的字段名称是“data.aut o completeData;”。

于 2012-07-03T06:51:57.453 回答