2012-05-28 69 views
0

我想查找XMLListCollection上的特定值。XMLListCollection查找索引值

我嘗試使用這樣的東西,但它不工作!

var xmllisteRDV:XMLList= XML(event.result).RDVClinik; 
xmlCollSuivi = new XMLListCollection(xmllisteRDV); 
var index:Number = -1; 
for(var i:Number = 0; i < xmllisteRDV.length(); i++) 
{ 
    if(XML(xmllisteRDV[i])[email protected] == todayDate) 
    { 
     index = i; 
     break; 
    } 
} 

回答

0

首先將嘗試在原有的代碼並指出錯誤:

var xmllisteRDV:XMLList= XML(event.result).RDVClinik; //Unnecessary cast, event.result is Object compiler will not check or know the run-time type, doesn't care because Object is declared dynamic meaning properties can be added to it dynamically, if RDVClinik didn't exist on the particular Object type it would simply be null casting as XML gives it no information about this "property" 
xmlCollSuivi = new XMLListCollection(xmllisteRDV); 
var index:Number = -1; 
     for(var i:Number = 0; i < xmllisteRDV.length(); i++) //length is a property not a method on XMLListCollection this should throw a compile time error 
     { 
      if(XML(xmllisteRDV[i])[email protected] == todayDate)// I see no type when debugging for the result of xmllisteRDV[i] not positive here but this cast is at the least unnecessary 
      { 
       index = i; 
       break; 
      } 
     } 

這裏有一個版本,我認爲將改變todayDate是如何構建的

var date:Date = new Date(); 
var todayDate:String = date.dateUTC+"/"+date.dayUTC+"/"+date.fullYear; 
var index:int=-1; 
for(var i:int = 0; i < flex3Projects.length; i++) 
{ 
    trace(xmllisteRDV[i][email protected]) 
    if(xmllisteRDV[i][email protected]() == todayDate) 
    { 
     index = i; 
     break; 
    } 
} 
0

有了你可能工作幫助,我找到了解決方案

private function setSelectedItem():void 
{ 
    var gData:Object = dgSuiviClini.dataProvider; 
    var todayDate:String= new DateUtility().DateAsToString(new Date()); 

    for(var i:Number=0; i < gData.length; i++) 
    { 
     var thisObj:Object = gData.getItemAt(i); 
     if(thisObj.grDateDeb == todayDate) 
     { 
      dgSuiviClini.selectedIndex = i; 
      //sometimes scrollToIndex doesnt work if validateNow() not done 
      dgSuiviClini.validateNow(); 
       //dgSuiviClini.scrollToIndex(i); 
     } 
     else{ 
      dgSuiviClini.validateNow(); 
       // dgSuiviClini.scrollToIndex(gData.length); 


     } 
    } 
    dgSuiviClini.validateNow(); 
    dgSuiviClini.editedItemPosition = { rowIndex: gData.length-1, columnIndex: nColSaisie }; 


} 

謝謝