Copy link to clipboard
Copied
Hi
The normal method to load data from php in to a datgrid is to push it into and array first...:
for(var i:uint=0; i<event.target.data.dgRows; i++)
{
dgArr.push
({
id:event.target.data["id"+i],
dateLogged:event.target.data["dateLogged"+i],
quoteNumber:event.target.data["quoteNumber"+i],
clientPoNum:event.target.data["clientPoNum"+i],
compName:event.target.data["compName"+i],
exclusive:event.target.data["exclusive"+i],
TAX:event.target.data["TAX"+i],
inclusive:event.target.data["inclusive"+i]
});
}
DG1.dataProvider = new DataProvider(dgArr);
What I'd like to know is if it is possible to pass "event.target.data" directly as a dataprovider, tried this but didn't work for obvious reasons: DG1.dataProvider = new DataProvider(event.target.data);
Basically I want code that doesn't have to change for each php file and reduce the amount of coding lines eg. I want to eliminate\change to 'dynamic':
"for(var i:uint=0; i<event.target.data.dgRows; i++) {dgArr.push({ ....... });"
Something like this would be awesome...
for(var key:String in map)
{
dgArr.push
({
key : map[key]
});
}
(the above code will add a row for each key which actually represent a column which is totally not what is required and is empty because the "key" must indicate.... )
Help will be appriciated
You can use the native JSON encoding functions in PHP to wrap your results in an object that can use the native JSON decoding functions in AS3 to turn it back into an array which can be used as a dataProvider.
You can also of course write the logic to wrap your results in XML from PHP and use that directly as a dataProvider.
Just set the proper MIME type for what you're sending and use normal string receive mode. e.g. return as XML and myGrid.dataProvider = XML(e.target.data); or return JSON and
...Copy link to clipboard
Copied
yes, if your php returned the data in an appropriate xml format.
Copy link to clipboard
Copied
You can use the native JSON encoding functions in PHP to wrap your results in an object that can use the native JSON decoding functions in AS3 to turn it back into an array which can be used as a dataProvider.
You can also of course write the logic to wrap your results in XML from PHP and use that directly as a dataProvider.
Just set the proper MIME type for what you're sending and use normal string receive mode. e.g. return as XML and myGrid.dataProvider = XML(e.target.data); or return JSON and myGrid.dataProvider = JSON.parse(e.target.data);
edit:
Haha do you ever sleep kglad..
Copy link to clipboard
Copied
(yes, but i awaken early. it's the curse of being an md. even when i don't have to do anything in the morning, i still am unable to sleep-in. but i can sure fall asleep watching tv at just about any time.)
Copy link to clipboard
Copied
lol - I've often wondered that my self - thanks a mil to both you guys, awesome as alway!!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
You're welcome and good luck! (I for the record would go JSON as there's native encoders on both sides making it really, really easy).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now