1 Reply Latest reply on Oct 17, 2009 8:38 PM by Shongrunden

    Delete an item in an XMLList by matching parameter?

    Handycam Level 1

      I am trying to write a function in an item handler that will delete an item in a dataprovider that matches an attribute (xml) of the item from the renderer.

       

      For example, let's say I have a data provider XMLList of memberList :

      <member name="john" memberid="100"/>

      <member name="john" memberid="101"/>

      <member name="fred" memberid="102"/>

      <member name="harry" memberid="103"/>

       

      The Spark list displaying this has a button to remove the current member:

      <s:HGroup>

      <s:Label text="{XML(data).name}" />

      <s:Button id="remove" label="Revoke Membership"  click="deleteItem()"/>

      </s:HGroup>

       

      My function is:

      public function deleteItem():void {
           var parentList:List = owner as List;
           // original blind code that removed the item from display only
           //parentList.dataProvider.removeItemAt(parentList.dataProvider.getItemIndex(data));
           var i:int = parentList.dataProvider.getItemIndex(data);
           var s:String = parentList.dataProvider.getItemAt(i).memberid;
           var x:XMLList = FlexGlobals.topLevelApplication.memberList;
           trace("X= "+x);
           trace("item title= "+parentList.dataProvider.getItemAt(i).memberid);
           trace("same as above= "+s);
      }
      

      Everything is tracing correctly, so it's working.  What I want to do is delete the node/member in the Global memberList where @memberid==s but I'm not sure of the syntax to set that up.