Can't access children of arrayCollection in datagrid

I have a Flex 3 app with HTTPService returning an Atom feed. I get the result from it and store it in arrayCollection which is then the provider of my Datagrid. I have no problem accessing data from the "first level" of my array, but I cannot get through. Not entirely clear, so this is the code:

My XML [part of it]:

<entry>
<title>Test 2</title>
<id>http://collaboration.*****.com/collaboration/messaging/feeds/****/todo//7D6637D3E86B3ED3C12575B***8479</id>
<link rel="alternate" href="notes:///C12575B4004***8/0/7D6637D3E86B3ED3C12575B6004E8479" type="application/vnd.lotus-notes"/>
<published>2009-05-14T16:17:37+02:00</published>
<updated>2009-05-14T16:17:56+02:00</updated>
<clb:todo>
<clb:uid>7D66***3ED3C12575B6004E8479</clb:uid>
<clb:due>2009-05-31T12:01:00+02:00</clb:due>
<clb:status>Not Started</clb:status>
</clb:todo>
</entry>

      

My Datagrid Code:

        <mx:AdvancedDataGrid y="10" id="notesGrid" width="90%" height="243" designViewDataType="flat" x="10" selectionMode="multipleRows" dataProvider="{notesArray}" >
            <mx:columns>
                <mx:AdvancedDataGridColumn 
                    headerText="TITRE" 
                    dataField="title" 
                    fontWeight="bold"
                 />
                <mx:AdvancedDataGridColumn headerText="STATUT" dataField="todo.status"/>
            </mx:columns>
        </mx:AdvancedDataGrid>

      

The title column displays data correctly, but the status column is empty! When I run my application in debug mode, I see that my Array notes are in the correct format and I can access todo -> status with the value ...

I've been stuck on this for a few days, I would appreciate any help! Thanks and best wishes!

0


a source to share


3 answers


The general rule of thumb that I follow when it comes to problems like this is to do something like this (just to make sure you get what you are looking for):

import flash.utils.getQualifiedClassName;

// As a general rule, I don't find it the best idea to access an object in 
// an IList (ArrayCollection, XMLListCollection, et al ) by a dynamic property.
// Especially when they are coming from XML, the best way to access everything 
// is through getItemAt.
var len:int = todo.length;
for( var i:int = 0; i < len; i++ )
{
    var item:* = todo.getItemAt( i );
    trace( item, getQualifiedClassName( item ) );
}

      

After that, my first attempt will replace this:

<mx:AdvancedDataGridColumn headerText="STATUT" dataField="todo.status"/>

      



with this:

<mx:AdvancedDataGridColumn headerText="STATUT" dataField="{ todo.status }"/>

      

Very often Flex doesn't work well with nested properties at all, but when you use parentheses, it gives a value that is at that point as a more direct reference.

I think you are also better off using XMLListCollection over ArrayCollection. This way you can call children by name instead of relying on their normal index in the IList.

0


a source


It might have something to do with the "status" node using a different "clb" namespace than your name. You may need to specify a namespace in order to access them.

I needed to do something similar when fetching XML data from a .NET WebService. It took me a few days to figure it out.

If your XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<atomFeed xmlns:clb="CLB.data">
    <entry>
    <title>Test 2</title>
    <id>http://collaboration.*****.com/collaboration/messaging/feeds/****/todo//7D6637D3E86B3ED3C12575B***8479</id>
    <link rel="alternate" href="notes:///C12575B4004***8/0/7D6637D3E86B3ED3C12575B6004E8479" type="application/vnd.lotus-notes"/>
    <published>2009-05-14T16:17:37+02:00</published>
    <updated>2009-05-14T16:17:56+02:00</updated>
    <clb:todo>
    <clb:uid>7D66***3ED3C12575B6004E8479</clb:uid>
    <clb:due>2009-05-31T12:01:00+02:00</clb:due>
    <clb:status>Not Started</clb:status>
    </clb:todo>
    </entry>
</atomFeed>

      

Add this to ActionScript where you process the HTTPService result:

private namespace clbNS = "CLB.data";

use namespace clbNS;

      



For instance:

package {import mx.rpc.events.ResultEvent;

public class handleAtomFeed
{
    private namespace clbNS = "CLB.data";

    use namespace clbNS;

    private function resultHandler(event:ResultEvent):void
    {
        // pares the XML and build your ArrayCollection
    }
}

      

}

Give him a shot, he just might work !!!

0


a source


I'm pretty sure the dataField DataGridColumn / AdvancedDataGridColumn property does not automatically allow nested properties, ie "todo.status"; you can try writing a labelFunction that will access the nested XML element for you.

0


a source







All Articles