JQuery UI Autocompletion - Adding a action link to

2019-09-22 02:38发布

问题:

i would like to modify my resultlist in the jquery UI autocomplete component in such a way, that i achieve the following:

label resulting_text actionlink

Is that somehow possible or do i need to do some monkey-patching? If monkey-patching is the action, where do i get a resource to look how this can be modified?

Thank you for your thoughts, Ramo

回答1:

Assuming that you would like to do this for all the autocomplete components on the page, I'd modify the "_renderItem" property. It is a function that is called by jquery UI to render each of the items on the list that is shown to the user with the results.

I've done something similar to this in one of my projects. Here is the code I used:

$.ui.autocomplete.prototype._renderItem = function (ul, item) {
    return $('<li />').data('item.autocomplete', item).append('<a>' + item.toString().htmlEncode() + '</a>')
        .appendTo(ul);
};