开发者

Flex : Add elements to XMLListCollection?

I have a MenuBar, which is using a XMLListCollection object as a dataProvider. I wish to add and remove elements from this collection at run开发者_运维问答time.

  • How to add / remove elements from XMLListCollection ?

// all suggestions which will improve the main idea is more than appreciated. :)


For me personally, it's easier to use an ArrayCollection as a dataprovider. You can use ArrayCollections as long as your objects have the "children" property, the children array will become your submenus. If working with ArrayCollections is easier for you, this may be a good route. Here's a good example of that: http://flexoop.com/2008/11/databinding-with-menubar-dataprovider/

You can modify XML/XMLLists easily using e4x. Here's a link on how to work with XML/XMLList: http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_03.html

There's a function called appendChild and you can delete nodes by simply using the delete keyword on a selected node.

delete someXML.someChild[0];

Here's a good article on working with XML: http://blogs.4point.com/armaghan.chaudhary/2009/08/xml-manipulation-in-flex-and-actionscript.html

XML functions/techniques should work fine with XMLList (and XMLListCollection).


To add

collectionName.addChild(o:object)

To remove

collectionName.removeChild(index:int);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜