Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery-自动完成上的Select函数未被调用?_Jquery_Autocomplete - Fatal编程技术网

JQuery-自动完成上的Select函数未被调用?

JQuery-自动完成上的Select函数未被调用?,jquery,autocomplete,Jquery,Autocomplete,我有下面的代码将自动完成添加到我的文本框中,自动完成显示出来,一切正常,但是当用户选择一个项目时,选择回调不会被调用? 有什么解决办法吗 $(function() { $("#txtItem").autocomplete({ minLength: 1, source: function (request, response) { $.ajax({ url: "/Correct url here", dataType

我有下面的代码将自动完成添加到我的文本框中,自动完成显示出来,一切正常,但是当用户选择一个项目时,选择回调不会被调用? 有什么解决办法吗

$(function() {

$("#txtItem").autocomplete({
    minLength: 1,
    source: function (request, response) {
        $.ajax({
            url: "/Correct url here",
            dataType: "json",
            data: {
                term: request.term
            },
            success: function (data) {
                response($.map(data, function (item) {
                    return {
                        label: item.Name,
                        value: item.Name
                    }
                }))
            },
            select: function (event, ui) {
                alert("sdfsdf");
                //$("#txtItemId").val(ui.item.value.ItemId);
            }
        })
    }
})

}

将代码重写为如下所示:

$(function() {

$("#txtItem").autocomplete({
    minLength: 1,
    source: function (request, response) {
        $.ajax({
            url: "/Correct url here",
            dataType: "json",
            data: {
                term: request.term
            },
            success: function (data) {
                response($.map(data, function (item) {
                    return {
                        label: item.Name,
                        value: item.Name
                    }
                }))
            }            
        })
    },
    select: function (event, ui) {
        alert("sdfsdf");
        //$("#txtItemId").val(ui.item.value.ItemId);
    }
})

}

让我知道它是否有效

请将代码改写为以下内容:

$(function() {

$("#txtItem").autocomplete({
    minLength: 1,
    source: function (request, response) {
        $.ajax({
            url: "/Correct url here",
            dataType: "json",
            data: {
                term: request.term
            },
            success: function (data) {
                response($.map(data, function (item) {
                    return {
                        label: item.Name,
                        value: item.Name
                    }
                }))
            }            
        })
    },
    select: function (event, ui) {
        alert("sdfsdf");
        //$("#txtItemId").val(ui.item.value.ItemId);
    }
})

}
$(function() {

$("#txtItem").autocomplete({
minLength: 1,
source: function (request, response) {
    $.ajax({
        url: "/Correct url here",
        dataType: "json",
        data: {
            term: request.term
        },
        success: function (data) {
            response($.map(data, function (item) {
                return {
                    label: item.Name,
                    ItemId: item.ItemId//this is will put item id in memory
                }
            }))
        }            
    })
},//this is after the source property select is an auto complete property many examples screw this up and it is in side the ajax block of code
select: function (event, ui) {
    alert("sdfsdf");
    //$("#txtItemId").val(ui.item.value.ItemId);
  }
  })}
让我知道它是否有效

$(function() {

$("#txtItem").autocomplete({
minLength: 1,
source: function (request, response) {
    $.ajax({
        url: "/Correct url here",
        dataType: "json",
        data: {
            term: request.term
        },
        success: function (data) {
            response($.map(data, function (item) {
                return {
                    label: item.Name,
                    ItemId: item.ItemId//this is will put item id in memory
                }
            }))
        }            
    })
},//this is after the source property select is an auto complete property many examples screw this up and it is in side the ajax block of code
select: function (event, ui) {
    alert("sdfsdf");
    //$("#txtItemId").val(ui.item.value.ItemId);
  }
  })}
下面是一个工作示例


下面是一个工作示例

您的选择是ajax调用的参数,而不是自动完成调用的参数。@cjc343不敢相信我花了两个小时才找到答案。感谢您的选择是ajax调用的一个参数,而不是自动完成调用的参数。@cjc343真不敢相信我花了两个小时才找到答案。谢天谢地,仍然缺少一组分号。@cjc343但它仍然有效Javascript仍然缺少一组分号。@cjc343但它仍然有效Javascript