Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dataprovider question

Explorer ,
Jan 16, 2013 Jan 16, 2013

Hi

Just a small area of dataProvider code I am 5% unsure of.

When you populate a provider with an object, eg...

myData = JSON.parse(event.target.data);// add JSON to object

listDP = new DataProvider(myData);// add object to dataProvider

data_grid.dataProvider = listDP;//set datagrid's dataProvider

...when you are making edits to the data, do you edit myData, and then to update the dataProvider...

listDP = new DataProvider(myData);// update dataProvider

...or do you somehow edit listDP directly?

Another way to ask...

...if the above was in an editable datagrid, when you make an edit, does Flash update myData, then do listDP = new DataProvider(myData); , or does it directly edit listDP?

Thanks guys

TOPICS
ActionScript
911
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 16, 2013 Jan 16, 2013

the dataProvider property of your datagrid will update so you would use:

listDP=data_grid.dataProvidier

to update listDP (which does not save json data anywhere).

Translate
Community Expert ,
Jan 16, 2013 Jan 16, 2013

the dataProvider property of your datagrid will update so you would use:

listDP=data_grid.dataProvidier

to update listDP (which does not save json data anywhere).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 18, 2013 Jan 18, 2013

Thanks kGlad

What if I'm not editing in the datagrid, but programatically adding data to it (from an external source)...

Example set up:

myData = JSON.parse(event.target.data);// add JSON to object

listDP = new DataProvider(myData);// add object to dataProvider

data_grid.dataProvider = listDP;//set datagrid's dataProvider

...and then I get some external data that needs to be added, do I add it to myData, or listDP? Currently I'm adding it to myData, then re-adding the line listDP = new DataProvider(myData); to update the datagrid.  Should I just be adding the data directly to listDP, and not myData?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2013 Jan 18, 2013

you could do that, you could add data directly to listDP and you could add the data directly to data_grid.

i would use one of the latter two because i don't like creating new objects unless necessary.  you're not creating a potential memory problem with that because you use the same variable (listDP) but you will be adding additional (over the latter two methods) work for garbage collection.  but i don't foresee a performance problem creating new listDP objects unless you're doing that frequently.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 20, 2013 Jan 20, 2013

I'm still confused mate.

myData = JSON.parse(event.target.data);// add JSON to myData array

listDP = new DataProvider(myData);// add array to dataProvider

data_grid.dataProvider = listDP;//set datagrid's dataProvider

Now when I try to access the dataProvider like...

trace(listDP[0].keyName);

...I get 'Property 0 not found on fl.data.DataProvider'

If I populated listDP with an array, and want to directly edit listDP, why does listDP[0] throw an error? Isn't the dataProvider an array?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2013 Jan 20, 2013

a dataprovider is not an array.  it doesn't have array methods.  even if you used an array to define a dataprovider (which you did not), you can't use array methods.

use the dataprovider methods like getItemAt:

trace(listDP.getItemAt(0).keyName)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 20, 2013 Jan 20, 2013

That just opened up a whole world for me. Thanks kGlad!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2013 Jan 20, 2013
LATEST

you're welcome.

p.s.  use the adobe help files.  the as3 class reference file contains a wealth of information.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines