3 Replies Latest reply on Sep 22, 2009 11:31 AM by Flex harUI

    Display an E4X conditional in a list?

    Handycam Level 1

      I have an XML list which is a series of times:

      <time label="3 hours ahead">here is bourbon sweet potatoes 3 hours ahead</time>

      <time label="2 hours ahead">stuff to do two hours ahead</time>

      <time label="3 hours ahead">here is  the stuffing 3 hours ahead</time>

      etc.

       

      I have a list in which I want to display all the node data that matches nodes with the label "3 hours ahead".

       

      I can trace(scheduleList.(@label=="3 hours ahead")) and get

       

       

      <time label="3 hours ahead">here is bourbon sweet potatoes 3 hours ahead</time>

      <time label="3 hours ahead">here is  the stuffing 3 hours ahead</time>

       

      in the console.

       

       

      I want to have the list display:

      here is bourbon sweet potatoes 3 hours ahead

      here is  the stuffing 3 hours ahead

       

      Can this be done on the fly, using just the one XMLList "scheduleList", or do I need to create a variable for each and every condition, such as:

       

      var threeHours:XMLList = scheduleList.(@label=="3 hours ahead")

       

      I am hoping it's the former, as I have several of these and would rather not have a bindable variable for each period of time.

        • 1. Re: Display an E4X conditional in a list?
          Flex harUI Adobe Employee

          var HandyCam:String = "3 hours ahead"

           

          scheduleList.(@label==HandyCam)

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Display an E4X conditional in a list?
            Handycam Level 1

            Thanks Alex, but even the way I had it works, I don't need a variable for it.

             

            My question was, can I merely assign the same XMLList as the data provider for several lists whilst displaying a different conditional for each.

             

            Pseudo-code:

             

            <datagrid id="threehourstuff" dataprovider="{shoppingXMLList}">

                 <datagridcolumn datafield="@label=='3 hours'">

            </datagrid>

             

            <datagrid id="twohourstuff" dataprovider="{shoppingXMLList}">

                 <datagridcolumn datafield="@label=='2 hours'">

            </datagrid>

            Does that make sense?  (I know this is not valid code, it was just for concept).

            • 3. Re: Display an E4X conditional in a list?
              Flex harUI Adobe Employee

              Sorry, I probably read too fast.

               

              An XMLList just "data".  For mx components, the dataProvider will wrap "data" in an ICollectionView, a view of the data, in this case an XMLListCollection.  For spark components you have to do the wrapping yourself.

               

              It looks like you want each datagrid to have its own view of the raw data.  Something to consider:  Does any other control or your code need access to the same view?  Usually the answer is yes so you are better off defining the XMLListCollections in your code.  Another thing to consider:  Do does any other part of your code need the filtered raw data?

               

              So, for some starting XML, you could create multiple XMLLists that contain the filtered raw data and assign the right one the right datagrid, or create one XMLList that is unfiltered, pass the same XMLList to each datagrid and then access the datagrid's dataProvider and apply a filter, or create multiple XMLListCollections based on the same XMLList and apply filters to those then assign the right one to the right datagrid or create multiple XMLListCollections based on different XMLLists.

               

              You won't need to implement any filtering statements in the DataGridColumn datafield.

               

              I think I'd do the latter (multiple XMLListCollections each with their own XMLList).  You're likely to want to work with that collection elsewhere in your code someday.

               

              var threeHourTasks:XMLListCollection = new XMLListCollection(rawXML.(@label=='3 hours'));

              var twoHourTasks:XMLListCollection = new XMLListCollection(rawXML.(@label=='2 hours'));

               

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui