jQuery UI autocomplete with item and id

前端 未结 11 1821
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 00:32

I have the following script which works with a 1 dimensional array. Is it possible to get this to work with a 2 dimensional array? Then whichever item is selected, by clic

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 00:47

    I've tried above code displaying (value or ID) in text-box insted of Label text. After that I've tried event.preventDefault() it's working perfectly...

    var e = [{"label":"PHP","value":"1"},{"label":"Java","value":"2"}]
    
    $(".jquery-autocomplete").autocomplete({
        source: e,select: function( event, ui ) {
            event.preventDefault();
            $('.jquery-autocomplete').val(ui.item.label);
            console.log(ui.item.label);
            console.log(ui.item.value);
        }
    });
    

提交回复
热议问题