1

如何默认选择列表中的项目

默认选定的项目说索引 0

我试过这样的东西——

listid.selectedIndex = somevalueinmyprogram - 1; // 0

但是当我调试这个时,我得到
_selectedIndex = 0 selectedIndex = -1

和默认值没有选择为什么会这样?[我已经检查了 somevaluefrommyprogram 显然不等于 0]

帮助!

4

1 回答 1

1

我发现如果你通过定义一个选定项的数组来设置 selectedItems,它比 selectedIndex 效果更好。

function setSelectedCategories():void{
   var selectedItems :Array = new Array();      
   for each (var selectedCategory:Category in entry.categories)      {
         for each (var category:Category in categories)         {       
              if (selectedCategory.categoryID == category.categoryID){
                     selectedItems .push(category);               
                     break; 
              }       
         }   
   }   

   categoriesList.selectedItems = selectedItems ;
}

如果要使用包含要选择的索引的数组,或者使用 selectedIndices 有效。

for ( var i:int=0; i < userIpods.length; i++ ) {

     //j will represent the list item's index value

     for ( var j:int = 0; j < iPodAry.length; j++) {

         if ( userIpods[i] == iPodAry[j].id ) {

         selectedIpodIndices.push( j );
         break;

         } //end if

     } //end for ( var iPodObj:Object in iPodAry) {


} //end for ( var i:int in userIpods ) 


/*mark as selected those index values in the 
selectedIpodIndices array*/

iPodList.selectedIndices = selectedIpodIndices ;
于 2009-06-20T18:34:46.123 回答