[jQuery] [Autocomplete] Incorrect handling of JSON objects/ Serialized Arrays

[jQuery] [Autocomplete] Incorrect handling of JSON objects/ Serialized Arrays


Great plugin except for one thing, won't handle JSON objects, or more
accurately Serialized arrays correctly.
I wrote a quick patch that modified the parse function within the
autocomplete plugin ...
==================
<code>
function parse(data) {
        var parsed = [];
        if( (typeof data) == "object" ){
            //var rows = data;
            $.each( data, function( i, val){
                parsed[parsed.length] = {
                    data: val,
                    value: i,
                    result: options.formatResult && options.formatResult(val, i) ||
i
                }
            });
        }
        else{
            var rows = data.split("\n");
            for (var i=0; i < rows.length; i++) {
                var row = $.trim(rows[i]);
                if (row) {
                    row = row.split("|");
                    parsed[parsed.length] = {
                        data: row,
                        value: row[0],
                        result: options.formatResult && options.formatResult(row,
row[0]) || row[0]
                    };
                }
            }
        }
        console.log(parsed);
        return parsed;
    };
</code>
===================
Your 'formatitem' callback should now get a js object on each call.
Also this works with JSON'd cakephp datasets ^_^
ie if we had a table with a post.name field i could get in my js
callback like so
<code>
bar(cakeObj, i, max){
return cakeObj.Post.name;
}
</code>