我正在尝试循环遍历 XMLList,而不是以 XML 形式提供列表中的每个项目,而是以字符串形式返回位置,例如
var myList:XMLList = ...(包含 < ;Type>DogCat)
for(var item in myList) {
Alert.show(item);
}
它仅提醒“0”或“1”。如果我检查“item”变量,我会看到同样的事情。但如果我检查“myList”,它看起来就像 XML。
我还尝试过 myList.children() 并将“items”强制键入“XML”,但我所做的一切都不起作用。
如果有人能告诉我正确的方法,我将非常感激。
谢谢
I'm trying to loop through an XMLList and rather than giving me each item in the list as XML, it's just coming back with the positions as strings e.g.
var myList:XMLList = ... (contains <Animal><Type>Dog</Type></Animal><Animal><Type>Cat</Type></Animal>)
for(var item in myList) {
Alert.show(item);
}
It just alerts "0" or "1". If I inspect the 'item' variable, I see the same thing. But if I inspect 'myList' it looks like the XML.
I've also tried myList.children() and strongly typing 'items' to 'XML' but nothing I do has worked.
Would really appreciate it if someone can tell me the right way to do it.
Thanks
发布评论
评论(3)
尝试使用下面的代码来获取 Dog 和 Cat。
Try the code below to get just Dog and Cat.
尝试使用
for every
而不是for
Try
for each
instead offor
由于它返回索引,您可以直接在列表中引用它们:
这将打印出以下内容:
或者,您可以直接引用每个子元素的元素:
这会导致:
As it is returning indexes you can just reference them in the list directly:
This will print out the following:
Or, you can reference elements of each child directly:
Which results in: