0
我有一个XMLListCollection对象,其中包含具有ID属性的项目。我想通过id找到一个特定的项目,然后在集合中获取它的索引。 这样做是为了能够告诉comboBox(其dataProvider是XMLListCollection)要显示的项目的索引。获取XMLListCollection对象中第一个元素的索引条件
我有一个XMLListCollection对象,其中包含具有ID属性的项目。我想通过id找到一个特定的项目,然后在集合中获取它的索引。 这样做是为了能够告诉comboBox(其dataProvider是XMLListCollection)要显示的项目的索引。获取XMLListCollection对象中第一个元素的索引条件
看看是否有效:(用适当的标签名称替换'item')。
comboBox.selectedItem = XML(xmlListCol.source.item.(@id == requiredIndex));
如果没有,用这个:
var list:XMLList = xmlListCol.source;
var index:Number = -1;
for(i = 0; i < list.length(); i++)
if(XML(list[i])[email protected] == requiredID)
{
index = i;
break;
}
if(index != -1)
comboBox.selectedIndex = index;
else
//deal with it
我做的for循环。丑,但它的工作.. – luca 2009-10-14 16:48:15
你尝试单线的东西 - 它的工作? – Amarghosh 2009-10-15 04:46:25
顶部没有工作,但buttom工作对我来说好一点,虽然我不得不唠叨它。 谢谢! – Babyangle86 2010-03-13 09:51:43