Title: Create mx:Model statically vs Binding

Frankly I think you’re getting lucky that the direct XML works.  The DataGrid can’t handle the XML object because the properties and such don’t present themselves cleanly (you have to access childNodes, nodeName, nodeValue, etc).  That’s why HTTPService defaults to de-serialize into an object structure.

 

Matt

 


From: Tracy Spratt [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 02, 2005 8:04 PM
To: [email protected]
Subject: [flexcoders] Create mx:Model statically vs Binding

 

There are a few other threads about this, and I have never been comfortable with mx:Model so I decided to try to figure it out, but have been unsuccessful.  In the small sample app below, I have three datagrids.  One uses XML directly, one uses a mx:Model populated statically, and one uses a Model populated by binding the XML.

The direct XML and static model work but I must be missing something basic in the bound model: the DataGrid remains “desperately” empty.  Does anyone see the problem?

TIA,

Tracy

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"

                initialize="initApp()">

<mx:Script><![CDATA[

        private var gXMLDoc:XMLNode;

        private var gaXMLData:Array;

        private function initApp():Void

        {

                var sXML:String =

                        "<elements>" +

                                "<element Key='Key' Name='Name' Dir='Dir' lang='lang' nloc='nloc' " +

                                                "Anom='Anom' label='label0' />" +

                                "<element Key='BAT000000' Name='COA034' Dir='A1/PRG' lang='Cobol' " +

                                                "Anom='OK' label='label1' />" +

                        "<elements>"

                gXMLDoc = mx.utils.XMLUtil.createXML(sXML);

                gaXMLData = gXMLDoc.firstChild.childNodes

        }//

               

]]></mx:Script>

       

        <mx:Model id="modelXMLB">{gXMLDoc}</mx:Model>

       

        <mx:Model id="modelXML">

                <elements>

                        <element Key="Key" Name="Name" Dir="Dir" lang="lang" nloc="nloc"

                                        Anom="Anom" label="label0" />

                        <element Key="BAT000000" Name="COA034" Dir="A1/PRG" lang="Cobol"

                                        Anom="OK" label="label1" />

                </elements>

        </mx:Model>    

       

        <mx:DataGrid id="dgSource" dataProvider="{gaXMLData}" rowCount="3">

           <mx:columns>

              <mx:Array>

                 <mx:DataGridColumn headerText="Key" columnName="Key" />

                 <mx:DataGridColumn headerText="Name" columnName="Name" />

                 <mx:DataGridColumn headerText="Dir" columnName="Dir" />

                 </mx:Array>

              </mx:columns>

           </mx:DataGrid>

               

       

        <mx:DataGrid id="dgSourceModelB" dataProvider="{modelXMLB.elements.element}" rowCount="3">

           <mx:columns>

              <mx:Array>

                 <mx:DataGridColumn headerText="Key" columnName="Key" />

                 <mx:DataGridColumn headerText="Name" columnName="Name" />

                 <mx:DataGridColumn headerText="Dir" columnName="Dir" />

                 </mx:Array>

              </mx:columns>

           </mx:DataGrid>      

               

        <mx:DataGrid id="dgSourceModel" dataProvider="{modelXML.elements.element}" rowCount="3">

           <mx:columns>

              <mx:Array>

                 <mx:DataGridColumn headerText="Key" columnName="Key" />

                 <mx:DataGridColumn headerText="Name" columnName="Name" />

                 <mx:DataGridColumn headerText="Dir" columnName="Dir" />

                 </mx:Array>

              </mx:columns>

           </mx:DataGrid>      

                               

                <mx:Button label="Button1" click="alert(modelXMLB.toString())"/>       

                <mx:Button label="Button2" click="alert(modelXML.toString())"/>

</mx:Application>



Reply via email to