3 Replies Latest reply on Nov 13, 2006 1:59 PM by ntsiii

    How Does On Reference An Array Of Objects?

    FlextasmicD
      Howdy!

      Ive read through Flex 2's help and also through the wonderful book 'Developing Rich Clients With Flex' for topics relating to this question but very strangely with no luck (and I assume it's quite straight forward)! So hopefully you chaps can help...

      Now, to get a value from an object model is very straight forward -
      quote:


      <mx:Model id="MyModel">
      <Inbox>
      <Message>
      <Sender>some@email.com</sender>
      <Subject>Blah Blah</Subject>
      <Content>This is the content of the email!</Content>
      </Message>
      </Inbox>
      </mx:Model>


      To get the <Sender> value its a simple case of -
      quote:


      MyModel.Inbox.Message.Sender


      Because obviously 'Sender' is just an object. But when I have an array of objects like so -
      quote:


      <mx:Model id="MyModel">
      <Inbox>
      <Message>
      <Sender>some@email.com</sender>
      <Subject>Blah Blah</Subject>
      <Content>This is the content of the email!</Content>
      </Message>
      <Message>
      <Sender>some@email.com</sender>
      <Subject>Blah Blah</Subject>
      <Content>This is the content of the email!</Content>
      </Message>
      </Inbox>
      </mx:Model>


      How do I reference the individual 'Sender' objects?

      Any help would really perk up my day :-)

      Thanks
        • 1. Re: How Does On Reference An Array Of Objects?
          ntsiii Level 3
          Try:
          MyModel.Inbox.Message.Sender[n]; //where "n" is the zero-based index of the element you want.

          Tracy

          Also, this is not a FlexBuilder question, so it should have been posted in the "General Discussion" forum instead of here.
          • 2. How Does On Reference An Array Of Objects?
            FlextasmicD Level 1
            Thank you kindly!

            Just one more question (i'd select a different forum but it's related to this)...

            How would I loop through e.g. MyModel.Inbox.Message.Sender[n], from within a dataProvidor for a repeator?

            I'm basically creating a UI which is based on template data stored in an external data model which is using nested loops -

            Data Model
            quote:

            <TemplatesConfigurator>
            <Template label="Elite II" table="tbl_Category" id="2" description="Elite II So Quote Template 00038_TMP_V9">
            <Category label="Heading - Base System Elite" table="tbl_CategorySub" id="1">
            <CategorySub label="Base System" table="tbl_CategorySub" id="4">
            <Parts1 label="08639" table="tbl_Template" id="1"></Parts1>
            </CategorySub>
            <CategorySub label="Elite II (included in base system)" table="tbl_CategorySub" id="5">
            <Parts1 label="05356" table="tbl_Template" id="2"></Parts1>
            <Parts1 label="03703" table="tbl_Template" id="3"></Parts1>
            <Parts1 label="05904" table="tbl_Template" id="4"></Parts1>
            <Parts1 label="06327" table="tbl_Template" id="5"></Parts1>
            <Parts1 label="06767" table="tbl_Template" id="6"></Parts1>
            </CategorySub>
            </Category>
            <Category label="Heading - Support Contracts & Warranty" table="tbl_CategorySub" id="28">
            <CategorySub label="Support Contract Options " table="tbl_CategorySub" id="29">
            </CategorySub>
            <CategorySub label="Warranty Options" table="tbl_CategorySub" id="30">
            </CategorySub>
            </Category>
            </Template>
            </TemplatesConfigurator>
            Repeaters
            quote:

            <mx:Repeater id="r1" dataProvider="{TemplateConfiguratorData.lastResult.TemplatesConfigurator.Template}">
            <mx:Form height="100%" width="100%" horizontalScrollPolicy="off" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" backgroundColor="#ffffff" verticalScrollPolicy="auto">
            <mx:Label text="{TemplateConfiguratorData.lastResult.TemplatesConfigurator.Template.label}" fontWeight="bold" fontSize="13" paddingBottom="0"/>
            <mx:Text text="{TemplateConfiguratorData.lastResult.TemplatesConfigurator.Template.description}" fontSize="10"/>

            <mx:Repeater id="r2" dataProvider="{TemplateConfiguratorData.lastResult.TemplatesConfigurator.Template.Categor y}">
            <mx:Label id="SubHeadings" text="{r2.currentItem.label}" fontWeight="bold" fontSize="12"/>

            <mx:Repeater id="r3" dataProvider="{ TemplateConfiguratorData.lastResult.TemplatesConfigurator.Template.Category[0].CategorySub}">
            <mx:Label text="{r3.currentItem.label}" fontWeight="bold" fontSize="10"/>
            </mx:Repeater>
            </mx:Repeater>

            </mx:Form>
            </mx:Repeater>
            • 3. Re: How Does On Reference An Array Of Objects?
              ntsiii Level 3
              If the repeaters are nested, then the data that creates them must be nested.

              So each nesting level's dataProvider specification must begin with the currentItem of the parent repeater.

              I can't be specific because you have not posted xml that shows the nested structure.

              Tracy