jQuery ui自动完成自定义数据呈现问题

时间:2013-02-04 10:16:29

标签: jquery jquery-ui

实际上我尝试了jquery自动完成项目类别。我有一个像这样的代码块,并尝试获取所选项目的id,这是附加的guaranter span的属性。那么当我从列表中选择一个类别时,如何获得id

JS CODE

$.widget("custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function (ul, items) {
        var that = this;
        $.each(items, function (index, item) {
            var li = that._renderItemData(ul, item);
            li.append('\
                <span style="font-size:10px; padding:2px;" class="guaranter" id="' + item.id + '">Guaranter:' + item.guaranter + '</span><br>\
                <span style="font-size:10px; padding:2px;">Father\'s Name:' + item.father_name + '</span><br>\
                <span style="font-size:10px; padding:2px;">District:' + item.district + '</span><br>\
                <span style="font-size:10px; padding:2px;"> National ID:' + item.national_info + '</span><br>\
                <span style="font-size:10px; padding:2px;">Contact:' + item.contact_number_personal + '</span>');
        });
    }
});

任何人都可以帮助我吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

选择你喜欢这样的李。

$(this).find('.guaranter').attr('id'); //here this is current selected li, you need to handle the event in select method. 
相关问题