I managed to alias some of the classes to more simple names in my WS,
so my JSON now looks like this.

{"persons":
        {"person":[
                {"personId__":
6,"firstName__":"Jack","lastName__":"Black","email__":"jbl...@jackblack.com"},
                {"personId__":
1,"firstName__":"Joe","lastName__":"Blow","email__":"jb...@hotmail.com"},
                {"personId__":
4,"firstName__":"Jason","lastName__":"Giambi","email__":"jgia...@yahoo.com"},
                {"personId__":
3,"firstName__":"Jim","lastName__":"Jones","email__":"jjo...@hotmail.com"},
                {"personId__":
5,"firstName__":"Jill","lastName__":"Robin","email__":"jro...@gmail.com"},
                {"personId__":
2,"firstName__":"Jason","lastName__":"Smith","email__":"jsm...@hq.nasa.gov"}
        ]}
}

I am still working on getting it parsed properly by overriding the
parse function in autocomplete, but I don't have it working yet. Any
assistance is appreciated!

jQuery("#pocEmail").autocomplete("../screen/PersonLookup", {
            width: 260,
            minChars: 1,
            cacheLength: 20,
            selectFirst: false,
            max: 25,
            dataType: "json",
            extraParams: {field2Use:'email',output:'json'},
            //formatResult: formatResult,
            //formatItem: formatItem,
            //formatMatch: formatMatch
            parse: autocompleteJSON,
            formatItem: function(row) {
                return row["email__"];
                //return row.firstName__ + " " + row.lastName__ + "["
+ row.email + "]";
            }
        });
      });

      var autocompleteJSON = function(data) {
        var json = data.persons.person;
        var parsed = [];
        for (var i=0; i < json.length; i++) {
            var row = json[i];
            parsed.push({
                data: row,
                value: row["firstName__"] + ' ' + row["lastName__"] +
' [' + row["email__"] + ']',
                result: row["email"]
            });
        }
        return parsed;
     };


On Feb 5, 10:32 am, zendog74 <n8cs...@gmail.com> wrote:
> What is the status of using remote JSON with jquery.autocomplete? I
> saw a couple of threads in the group about it, but they are patchworky
> and hard to follow. I did not see anything about using JSON on the
> autocomplete jquery plugin site. Is using remote JSON supported or do
> I have to modify source to make it work?
>
> Here is what I am trying to do. I created a WS to return some user
> data for an autocomplete. Here is the JSON that is returned when I
> type 'j' into my autocomplete form field.
>
> {"linked-list":{"gov.nasa.hq.portal.calendar.to.PersonTO":
> [{"personId__":
> 6,"firstName__":"Jack","lastName__":"Black","email__":"jbl...@jackblack.com"},
> {"personId__":
> 1,"firstName__":"Joe","lastName__":"Blow","email__":"jb...@hotmail.com"},
> {"personId__":
> 4,"firstName__":"Jason","lastName__":"Giambi","email__":"jgia...@yahoo.com"},
> {"personId__":
> 3,"firstName__":"Jim","lastName__":"Jones","email__":"jjo...@hotmail.com"},
> {"personId__":
> 5,"firstName__":"Jill","lastName__":"Robin","email__":"jro...@gmail.com"},
> {"personId__":
> 2,"firstName__":"Jason","lastName__":"Smith","email__":"jsm...@hq.nasa.gov"}]}}
>
> Here is my javascript:
>
> document.observe("dom:loaded", function() {
>
>         jQuery("#pocEmail").autocomplete("../screen/PersonLookup", {
>             width: 260,
>             minChars: 1,
>             cacheLength: 20,
>             selectFirst: false,
>             max: 25,
>             extraParams: {field2Use:'email',output:'json'},
>             formatItem: function(row, i, max) {
>                 alert(row);
>                 return row;
>                 //return row.firstName__ + " " + row.lastName__ + "["
> + row.email + "]";
>             }
>         });
>
> });
>
> The entire JSON is getting returned as a row, so I assume it is being
> treated as a String and is seen as one row.
>
> Can I make this work without too much hardship? The WS I created can
> return XML as well if that is an option.
>
> Thanks!

Reply via email to