开发者

jQuery-UI Autocompelete not showing results while typing

开发者 https://www.devze.com 2023-02-19 02:47 出处:网络
Im having some weird issues with the jquery autocomplete fu开发者_如何学编程nction on the jQuery UI.

Im having some weird issues with the jquery autocomplete fu开发者_如何学编程nction on the jQuery UI.

When I type in the input, I get no results, If I delete everything I typed, then the autocomplete results show up.

Also, the autocomplete does not seem to filter my results for matching characters.

I put the code on jsfiddle here. http://jsfiddle.net/wqgjL/

Here is the code with only part of the json object


var accounts = $.parseJSON('[{"id":"217","aid":"c4ca4238a0b923820dcc509a6f75849b","system_id":"6c907867-f687-67a9-c342-00001fa54bc1","account_id":"","account_type":"Other Income","account_name":"Proceeds from sale of assets","account_status":"Enabled"},{"id":"218","aid":"c4ca4238a0b923820dcc509a6f75849b","system_id":"542dd9ad-914c-2b69-ca3f-0000413ef162","account_id":"","account_type":"","account_name":"Other Expenses","account_status":"Enabled"},{"id":"211","aid":"c4ca4238a0b923820dcc509a6f75849b","system_id":"638336e9-3bdf-4329-7a15-000058ba48f2","account_id":"","account_type":"Expense","account_name":"Taxes","account_status":"Enabled"}]');

//alert(data);
$("#accountSearch").autocomplete({
    minLength: 0,
    source: accounts,
    focus: function(event, ui) {
        $("#accountSearch").val(ui.item.account_name);
        return false;
    },
    select: function(event, ui) {
        $("#accountSearch").val(ui.item.account_name);
        $("#jeAccountID").val(ui.item.system_id);

        return false;
    }
}).data("autocomplete")._renderItem = function(ul, item) {
    return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.account_name + "</a>").appendTo(ul);
};


Having label an value as JSON properties helps a lot with autocomplete, infact them are default properties for that widget. Here is a working example of your autocomplete:

http://jsfiddle.net/GCur5/

I've just changed your json's system_id in value and account_name in label.

Having done this some of your autocomplete funcions were trivial so that i've removed them.

0

精彩评论

暂无评论...
验证码 换一张
取 消