I have a method in a Flex 2 app that pulls in data from a view I've called products_all. Now some of the fields are returned as an Array, inside of Flex it says object. For example:

stdClass Object
(
[nid] => 4
[title] => 4GB MicroSD
[body] => 4GB MicroSD Card for use with your Blackberry Phone or any other compatible devices

[teaser] => 4GB MicroSD Card for use with your Blackberry Phone or any other compatible devices
[model] => bbz1234
[sell_price] => 60.00
[field_affiliate_price] => Array
(
[0] => Array
(
[value] => 1
)

)

[field_image_cache] => Array
(
[0] => Array
(
[fid] => 1
[title] => microSD 4GB.jpg
[alt] => microSD 4GB.jpg
[nid] => 4
[filename] => microSD 4GB.jpg
[filepath] => files/microSD 4GB.jpg
[filemime] => image/jpeg
[filesize] => 16687
)

)

[taxonomy] => Array
(
[11] => stdClass Object
(
[tid] => 11
[vid] => 2
[name] => Accessories
[description] =>
[weight] => 0
)

)

[field_coupon_code] => Array
(
[0] => Array
(
[value] => 0
)

)

[changed] => 1185392396
)

i want to be able to get to field_image_cache=> filepath

or any other field within an array, How do I do this?

Comments

Johannes De Boeck’s picture

hi,

I used to get the desired fields from the View via a RemoteObject and then call them like this:

public function getPhotos():void{
views.getView("nameOfYourView", ['nid','title','field_image_cache','filepath']);
}

In the MXML i would get the data like this:

toolTip="{data.title}"
data="http://www.myWebsite.com/{data.field_image_cache.filepath}"/>

don't know if this is 'good practice'..

funkyboy’s picture

Hello,

have you any how to about setting up views, format data in drupal to be 'used' by flex?

Thanks,

-c.

CHEETAH’s picture

Hey I am having a similar issue here. I've trying to research it, then put it off for a few months and am now still back on it. I discovered 'getItemIndex()' function. Look it up in adobe flex documentation, It is supposed to parse arrays as far as I can understand. I have not got it functioning, but this looks like it is something that could solve our problems. Let me know if you get anything working by using the above-stated function. Thanks a lot

rolodmonkey’s picture

I believe the correct syntax would be:


$path = $node->field_image_cache[0]['filepath'];

--

Read more at iRolo.net

CHEETAH’s picture

Hey I figured it out...
the syntax is as follows:
id="caption"
text="{DataGrid.selectedItem.field_caption[0]['value']}"
/>

Look at this example as if you had a text component and a CCK field called 'caption'.
'DataGrid' would be the name of your datagrid, which should be populated by the ArrayCollection that's holding your content that was requested from Drupal via the webservice.

If this is not clear, simply holla at me. I can give a more detailed explanation, but am too lazy to do so at the current moment.

Johannes De Boeck’s picture

can you please paste your code again? apparently if got lost somewhere.. tx

thewolrus’s picture

Can you please post the code again,

Thanx

CHEETAH’s picture

Wow, I just re-discovered this thread, now 17 months later...
The code that I posted previously must've gotten lost somehow...

I hope all of you have figured out a solution by now, but if not, I will re-post updated examples for connecting Flex datagrids with Objects returned from Drupal Services.
...soon

thewolrus’s picture

Some of you guys could find any solution to this issue?. I have exactly the same problem. I've created a custom service and a custom type in Drupal with CCK fields, this fields are in fact arrays, what is the best approach to get the info inside them?

nickgs’s picture

I am working on this now. I am using the function below in one of my classes to read the data into an ArrayCollection that is then bound to a DataGrid. The problem I am experiencing is cleaning up the objects before binding. I don't want my DataGrid headers to read node_data_field_name_field_name_value ... etc.

private function bindViewData(e:ResultEvent):void { 
     trace("Going to start binding some data."); 
				
     var resultObj:Object;  
				
     resultObj = e.result; 
				
     for (var item:String in resultObj) {			
          //this is where I would like to clean the headers (aka members) in the resultObj object. 
          //cleanHeaders(resultObj[item]); 
          
          //the ArrayCollection that is bound to the DataGrid. 	  				
          viewData.addItem(resultObj[item]);
					
          trace(ObjectUtil.toString(resultObj[item]));
     }
}

Hope this helps someone. Any ideas about the cleanHeaders function would be helpful!

Thanks.

Nick
nickgs.com

nickgs’s picture

I figured this out pretty well. I don't really have time to outline everything but if anyone want any help shoot me an email.

I hope to blog about this but I wouldn't hold your breath.

Nick
nickgs.com

CHEETAH’s picture

I haven't had time to dig up an example to post, but I will say this:
The solution to this confusion lies in 'item renderers'.
Once the Data Object is passed into the DataGrid via an ArrayCollection, you need to construct a Flex 'item renderer' to render the '[Object object]' that you currently see within the DataGrid

The item renderer can even be its own MXML file...
It should take a argument of the datatype 'Object' and it will render that Object as whatever media that you specify within the item renderer.

I hope this helps