0

我想在 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]).@grDateDeb == todayDate)
    {
        index = i;
        break;
    }
}
4

2 回答 2

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]).@grDateDeb == 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].@grDateDeb)
    if(xmllisteRDV[i].@grDateDeb.toString() == todayDate)
    {
        index = i;
        break;
    }
}
于 2012-05-29T00:06:40.533 回答
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 };


}

谢谢

于 2012-05-29T00:53:22.237 回答