i had exactly the same requirement

My solution was this:


adding an option called service like so:

$(".TagField input").autocomplete(null, {

                max: 20,
                highlight: false,
                multiple: true,
                multipleSeparator: ",",
                scroll: true,
                scrollHeight: 200,
        selectFirst:false,
        minChars:1,
        service:getData
    });

function getData(term,callback){
        var d=['mark','testies','tester','code','hello
world','hello','world'];

        var str="";
        function eachD(i,n){
            str+=n+"\n";
        }
        $.each(d,eachD);

        callback(str);
    }


... and changing the autocomplete code like so...


.....} else if((typeof options.service == "function")){
            options.service(lastWord(term),function(data){
                var parsed = options.parse && options.parse(data) ||
parse(data);
                cache.add(term, parsed);
                success(term, parsed);
            });

        } else {
                        // if we have a failure, we need to empty the list -- 
this prevents
the the [TAB] key from selecting the last successful match
                        select.em.....


the getData method has hard coded data at the minute as i havent
written the service and at the time of writing i am just testing it.

Having this flexibility allows me to abstract the data loading so i
can pull it from any data source, any data format and pass it into the
plugin in the format it requires




Hope this helps
On Jun 27, 8:16 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Jorn,  great work onautocomplete.
>
> One thing I'd like to see is the ability to pull the data from a
> function (instead of a static array or url).  The function could
> return the array instead, however it wanted to go get the data.
>
> Imagine:
>    autocomplete: function(urlOrDataOrFunction, options) {
>
> I tried to hack it in myself, making a function that returned an array
> of objects,using typeof urlOrData == 'function', and then invoking the
> function in the "function request(term, success, failure)"  section,
> but I failed.  Pretty spectacularly.  It seems like it should work,
> but later "item" (for formatItem) comes back undefined.  I'll keep
> working at it.

Reply via email to