代码之家  ›  专栏  ›  技术社区  ›  luca

获取第一个元素的索引以处理xmlListCollection对象中的条件

  •  0
  • luca  · 技术社区  · 15 年前

    我有一个XmlListCollection对象,其中包含具有ID属性的项。我想按ID找到一个特定的项,然后在集合中获取它的索引。 这样做是为了能够告诉组合框(其数据提供程序是xmlListCollection)要显示的项的索引。

    1 回复  |  直到 15 年前
        1
  •  2
  •   Amarghosh    15 年前

    看看这是否有效:(用适当的标记名替换“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]).@id == requiredID)
      {
        index = i;
        break;
      }
    if(index != -1)
      comboBox.selectedIndex = index;
    else
      //deal with it
    
    推荐文章