jquery autocomplete json and clickable link through

后端 未结 2 1568
野的像风
野的像风 2021-02-11 07:03

I\'ve been at this for a while and I\'m making very slow progress mostly because my jquery skills need improvement, I am trying though :)

I have this code:



        
2条回答
  •  庸人自扰
    2021-02-11 07:44

    The real issue for me is getting the JSON data from the response into the autocomplete results

    Just looking at your code, it looks like the autocomplete should be populating correctly. Are you sure the data is coming back? If you keep having problems, try using a local data source and see if the problems persist.

    if any of these are clicked it directs the page to data.url.

    You can accomplish this by defining an event handler for the select event:

    $("input").autocomplete({
        /* Snip */
        select: function(event, ui) {
            window.location = ui.item.url;
        }
    });
    

    ui.item refers to the item that was selected in the dropdown.

    Here's an example of this working (with a local data source):
    https://jsfiddle.net/gbdarren/k2q5rfdh/5/

提交回复
热议问题