无法选择自定义jquery自动完成项

时间:2014-01-23 22:19:21

标签: jquery jquery-ui autocomplete

任何人都可以帮我弄清楚为什么我无法选择任何自动完成项目?我正在尝试自定义项目的显示值。另外,为什么jquery仅匹配国家名称而不是id,即如果我输入17,我应该期待看到阿尔巴尼亚出现在选择中,但它不是吗?

http://jsfiddle.net/RTn4c/1/

$("#field").autocomplete({
    source: countries_starting_with_A,
    minLength: 1,
    select: function(event, ui) {
        // feed hidden id field
        $("#field_id").val(ui.item.id);
        // update number of returned rows
        $('#results_count').html('');
    },
    open: function(event, ui) {
        // update number of returned rows
        var len = $('.ui-autocomplete > li').length;
        $('#results_count').html('(#' + len + ')');
    },
    close: function(event, ui) {
        // update number of returned rows
        $('#results_count').html('');
    },
    // mustMatch implementation
    change: function (event, ui) {
        if (ui.item === null) {
            $(this).val('');
            $('#field_id').val('');
        }
    }
}).data("ui-autocomplete")._renderItem = function (ul, item) {

                return $("<li></li>")
                .append("<span>" + item.value + ' ' + item.id + " </span> ")
                .appendTo(ul);
            };

// mustMatch (no value) implementation
$("#field").focusout(function() {
    if ($("#field").val() === '') {
        $('#field_id').val('');
    }
});

});

0 个答案:

没有答案
相关问题