Hi Dhiren,

var obj = {prop1:10, prop2:20}

is equivalent to:

var obj = new Object();

obj.prop1 = 10;
obj.prop2 = 20;


And

var arr = [];

is equivalent to:

var arr = new Array();



So you can guess,

var dp =  [
                 {Name:"Dhiren", Age:20}        
            ];

is an array of object.


I guess, you can solve this problem by creating ValueObject in ActionScript
as well as in Java code:


##javacode##

package com.dhiren
public class DetailObject
{
        public String Name;
        public Integer Age;
        
        public DetailObject(String N, String A)
        {
                Name = N
                Age = A;
        }
}


DetailObject[] detailObjectArr = new DetailObject[2];

detailObjectArr [0] = new DetailObject("Dhiren", 20);
detailObjectArr [1] = new DetailObject("Abdul", 24);

Send this to client to Flash...


##flexcode##

class com.dhiren.DetailObject
{
        public var Name:String;
        public var Age:Number;
        
        public static var regClass =
Object.registerClass("com.dhiren.DetailObject", com.dhiren.DetailObject);

}


So now when flash would receive that array, class would automatically
mapped..

var detailValues = detailObjectArr;

dg.dataProvider = detailValues;


Look at this link for more:

http://livedocs.macromedia.com/flex/15/flex_docs_en/00002246.htm


-abdul



-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] 
Sent: Saturday, April 23, 2005 11:27 AM
To: [email protected]
Subject: Re: [flexcoders] Dymanic data/headers for DataGrid


Abdul,

The array is being returned directly from Java code. I cannot use this
notation in a Java object: {Name:"Dhiren", Age:20}. I am not
explicitly creating the array in ActionScript, it is being evaluated
automatically.

BTW, what does this signify? I ran your example and see that Name:
shows up on the column header. Can you point me to some documentation
regarding this notation?

On 4/22/05, Abdul Qabiz <[EMAIL PROTECTED]> wrote:
> 
> Hey Dhiren,
> 
> Folling is simple example, where you can switch dataProvider of datagrid
to
> two different Arrays with different structure of objects..One with two
> properties and other with three...
> 
> -abdul
> 
> ##DynamicDataGrid.mxml##
> 
> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
> creationComplete="onAppInit()">
>    <mx:Script>
>        <![CDATA[
> 
>            var dp1:Array;
>            var dp2:Array;
> 
>            function onAppInit()
>            {
>                dp1 = [
>                        {Name:"Dhiren", Age:20},
>                        {Name:"Abdul", Age:100}
> 
>                     ];
> 
>                dp2 =   [
>                            {Subject:"Physics", Marks:95, Rank:2},
>                            {Subject:"Maths", Marks:98, Rank:1}
>                        ];
> 
>            }
> 
>            function changeDP(which:Array)
>            {
>                dg.removeAllColumns();
>                dg.dataProvider = which;
>            }
> 
>        ]]>
>    </mx:Script>
> 
>    <mx:DataGrid id="dg" />
>    <mx:Button label="Set dataProvider = dp1" click="changeDP(dp1)" />
>    <mx:Button label="Set dataProvider = dp2" click="changeDP(dp2)" />
> </mx:Application>
> 
> 
> -abdul
> 
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED]
> Sent: Saturday, April 23, 2005 11:05 AM
> To: [email protected]
> Subject: RE: [flexcoders] Dymanic data/headers for DataGrid
> 
> What do you mean by 2d Object array?
> 
> Does your array look like this:
> 
> var dp =        [
>                        {Name:"Dhiren", Age:20},
>                        {Name:"Abdul", Age:23}
>                ];
> 
> -abdul
> 
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED]
> Sent: Saturday, April 23, 2005 10:34 AM
> To: [email protected]
> Subject: [flexcoders] Dymanic data/headers for DataGrid
> 
> Hi guys,
> 
> I'm sure this question has been asked before, however I can't find a
> suitable answer searching the forum.
> 
> What's the best way to display dynamic data resulting from a remote
> object in a DataGrid. I have no way of knowing the headers or the
> data which will result. I have it as follows now:
> 
> <mx:DataGrid id="dg3" dataProvider="{my_list.dataValues}">
> </mx:DataGrid>
> 
> dataValues is a 2D Object array containing Strings and Doubles.
> 
> This has a few problems:
> 
> 1. The data is displayed in opposite order. i.e. col 0 is displayed
> last and col n is displayed first.
> 
> 2. I cannot display headers.
> 
> Any help would be appreciated. Thanks.
> 
> Dhiren
> 
> Yahoo! Groups Links
> 
> Yahoo! Groups Links
> 
> Yahoo! Groups Links
> 
> 
> 
> 
>


 
Yahoo! Groups Links



 





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to