0 Replies Latest reply on Oct 31, 2010 5:26 AM by baazuigo

    how to binding incoming xml node list to the tree control as dataProvider

    baazuigo

      Recently, I faced into one issue: I want to binding incoming xml node (it's not avaliable at start) list to the tree control as a dataProvider.

      Since the incoming xml node list is not avaliable at beginning but I needs to bind it to the tree, so I create one virtual one in the xml, and prepare to remove it before the tree is shown. (ready for the actual node adding). But It did not work.

       

      Please see the presudo-code here:

       

      1.  Model layer(CsModel.as)
      public class CsModel
      {
              [Bindable]
              public var treeXML:XML=
      <nodes><car label="virtualOne" id="1">
                                     </car
      ></nodes>;
              (Here, I want to build binding relationship on the <car/> node,
               one 'virtual/stub' node is set here with lable="
      virtualOne".
               But this node will be deleted after IdTree
               control is created completely.)      

              [Bindable]
              public var treeData:XMLList =new XMLListCollection(treeXML.car);
      }

      2. view layer(treePage.mxml)
      ...
              private var _model:CsModel = new CsModel();
              private function addNode():void
                  {
                      var newNode:XML=
      <car/>;
                      newNode.@label="newOne";
                      newNode.@id=1;
                      _model.treeXML.appendChild(newNode);
                  }
                            
                               private function cleanData():void
                  {
                                       delete _model.treeXML.car;
                  }
      ...
             
      <mx:VBox height="100%" width="100%">
             
      <mx:Button label="AddNode" click="addNode()" />
             
      <mx:Tree id="IdTree"  labelField="@label"
                creationComplete
      ="cleanData()"
                dataProvider
      ="{_model}"/>
         
      </mx:VBox>

      3. Top view layer (App.Mxml)
      <mx:application>
         
      <treePage />
      </mx:application>

      For method: cleanData(),It's expected that when the treePage is shown, we first delete the virutalOne to provide one 'clear' tree since we don't want show virtualOne to the user. The virutalOne node just for building the relationship between treeData and treeXML at beginning. But the side effect of this method, I found, is that the relationship between treeXML and treeData was cut off. And this leads to that when I added new node (by click the 'addNode' button) to the xmlXML, the xmlData was not affected at all !

       

      So Is there any other way to solve this issue or bind the incoming xml node list to the xmlListCollection which will be used as Tree control's dataProvider ?