2 Replies Latest reply on May 24, 2008 8:51 AM by MayLam18

    E4X dot notation

    brad carvey-kplRXI
      I just got the Adobe Flex 3 "Training from the Source". I am trying to get the E4X dot notation working and the book has an excellent example for testing dot notation to generate a Tree List. Unfortunately, the example is written with Flex 2 and a commercial plugin.

      I have tried to create some simple code that would use a datagrid and allow dot notation in the datafield. I want to specify a single dataprovider and select datafield entries using dot notation.

      The code below does not display anything. If I ccange the dataProvider to "{groceryXML.category}", then change the first dataField to @name, I will get Vegetables and Fruit under the Category Header,but the "product@name" does not work.

      I can generate lots of dataProviders. I can also do this with an arrayCollection, but the book recommends using XML and not an arrayCollection. I also have some issues with how to get a differnent elements inside of the dataProvider when it is generated from an arrayCollection.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="800" height="286">

      <mx:Script>
      <![CDATA[

      [Bindable]
      public var groceryXML:XML =
      <catalog>
      <category name="vegetables">
      <product name="lettuce" cost="1.95">
      <unit>bag</unit>
      <desc>Cleaned and bagged</desc>
      </product>
      <product name="carrots" cost="2.95">
      <unit>pound</unit>
      <desc>Baby carrots, cleaned and peeled</desc>
      </product>
      </category>
      <category name="fruit">
      <product name="apples" cost="1.95">
      <unit>each</unit>
      <desc>Sweet Fuji</desc>
      </product>
      <berries>
      <product name="raspberries" cost="3.95">
      <unit>pint</unit>
      <desc>Firm and fresh</desc>
      </product>
      <product name="strawberries" cost="2.95">
      <unit>pint</unit>
      <desc>Deep red and juicy</desc>
      </product>
      </berries>
      </category>
      </catalog>;
      ]]>
      </mx:Script>

      <mx:Panel layout="absolute" left="10" top="10" right="10" bottom="10" title="Groceries">

      <mx:DataGrid id="groceryGrid" right="10" left="10" top="10" bottom="19"
      dataProvider="{groceryXML.category}">
      <mx:columns>
      <mx:DataGridColumn headerText="Category" dataField="@name"/>
      <mx:DataGridColumn headerText="Product" dataField="product@name"/>
      <mx:DataGridColumn headerText="Cost" dataField="product@cost"/>
      <mx:DataGridColumn headerText="Unit" dataField="product.unit"/>
      <mx:DataGridColumn headerText="Description" dataField="product.desc"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Panel>
      </mx:Application>


        • 1. E4X dot notation
          VarioPegged Level 2
          The dataField property of a DG column expects a string. When you do dataField="product.@name", you're trying to evaluate an E4X expression. You'd have to use label functions on the DG column(s) to evaluate the expression first and then have the function return a string.

          Since you're looking to display all products in the DG, you should make the "product" node the data provider, then you can evaluate the parent nodes via a label function. The XML was adjusted a bit for consistency.

          See the attached code.

          TS
          • 2. Re: E4X dot notation
            MayLam18 Level 1
            Thanks VarioPegged.

            Your code is very helpful to me.

            May