Il gruppo nel quale stai postando è un
gruppo Usenet . I messaggi postati in questo gruppo rendono la tua email visibile a chiunque su Internet
Il messaggio di risposta non è stato inviato.
Post riuscito
Da:
zendog74 <n8cs... @gmail.com>
Data: Thu, 5 Feb 2009 07:32:36 -0800 (PST)
Locale: Gio 5 Feb 2009 16:32
Oggetto: autocomplete and json
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!
Non sei autorizzato a postare messaggi.
Da:
zendog74 <n8cs... @gmail.com>
Data: Thu, 5 Feb 2009 12:42:00 -0800 (PST)
Oggetto: Re: autocomplete and json
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!
Non sei autorizzato a postare messaggi.
Da:
zendog74 <n8cs... @gmail.com>
Data: Thu, 19 Feb 2009 12:16:33 -0800 (PST)
Locale: Gio 19 Feb 2009 21:16
Oggetto: Re: autocomplete and json
FYI, I got this to work. Here is the code that I ended up with.
Perhaps it will help others who run across the same problem:
jQuery("#pocEmail").autocomplete ("../screen/PersonLookup", {
width: 275,
minChars: 1,
cacheLength: 25,
selectFirst: false,
max: 50,
dataType: "json ",
extraParams: {field2Use:'email',output:'json '},
//formatMatch: formatPocMatch,
//formatResult: formatPocResult,
parse: parsePocJSON,
formatItem: formatPocItem
});
jQuery("#pocEmail").result(formatPocResult);
function parsePocJSON(data) {
var json = data.persons.person;
var parsed = [];
if(json != undefined) {
//There are some matches
if(json .length != undefined) {
//There are multiple records
for (var i=0; i < json .length; i++) {
var row = json [i];
parsed.push({
data: row,
value: row["email__"],
result: row["email__"]
});
}
}else{
//There is a single record
parsed.push({
data: data.persons.person,
value: data.persons.person.email__,
result: data.persons.person.email__
});
}
}
return parsed;
}
function formatPocItem(row) {
return row["firstName__"] + ' ' + row["lastName__"] + ' [' +
row["email__"] + ']';
}
function formatPocResult(event, row, formatted) {
jQuery("#pocEmail").val(row["email__"]);
jQuery("#pocFname").val(row["firstName__"]);
jQuery("#pocLname").val(row["lastName__"]);
}
On Feb 5, 3:42 pm, zendog74 <n8cs... @gmail.com> wrote:
> I managed to alias some of the classes to more simple names in my WS,
> so myJSONnow 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 inautocomplete, 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) {
> varjson= 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 remoteJSONwith 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 usingJSONon the
> >autocompletejquery plugin site. Is using remoteJSONsupported 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 anautocomplete. Here is theJSONthat is returned when I
> > type 'j' into myautocompleteform 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 entireJSONis 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!
Non sei autorizzato a postare messaggi.
Da:
Jonny B <jonnybrad... @gmail.com>
Data: Fri, 27 Feb 2009 10:31:08 -0800 (PST)
Locale: Ven 27 Feb 2009 19:31
Oggetto: Re: autocomplete and json
Non sei autorizzato a postare messaggi.