-1

我尝试的任何方法都不起作用。我正在尝试排序然后将 XMLList 或 XMLListCollection 拼接到一些结果。

这是我的代码:

public function chopData(){

//pData = pDataCollection.source;
pData = sortXMLListByAttribute(filteredData, sortField);
var thisLength = pData.length();
trace("thisLength: " + thisLength);
var maxAmountToShow = 30;


if(thisLength == null){
    thisLength = maxAmountToShow;
}

if( thisLength < maxAmountToShow){
    pData = SliceXMLList(pData, 0, thisLength - 1);
    //pDataCollection = SpliceXMLListCollection(pDataCollection, 0, thisLength - 1);
}else{
    pData = SliceXMLList(pData, 0, maxAmountToShow - 1);
    //pDataCollection = SpliceXMLListCollection(pDataCollection, 0, maxAmountToShow - 1);
}


pDataCollection = new XMLListCollection(pData);

}


 public static function sortXMLListByAttribute
 (
    $xmlList        :   XMLList,
    $attribute  :   String,
    $options    :   Object  =   null
) :XMLList
 {
//store in array to sort on
var xmlArray:Array= new Array();
var item:XML;
for each(item in $xmlList)
{
    var object:Object = {
        data    : item, 
        order   : item.attribute($attribute)
    };
    xmlArray.push(object);
}

////sort using the power of Array.sortOn()
xmlArray.sortOn('order',$options);

////create a new XMLList with sorted XML
var sortedXmlList:XMLList = new XMLList();
var xmlObject:Object;
for each(xmlObject in xmlArray )
{
    sortedXmlList += xmlObject.data;
}
return sortedXmlList;   
}
4

1 回答 1

0

我发现了这个 com.maximporges.MaskedCollection 类,它运行良好。

http://dreamingwell.com/examples/flex/scrollableGraph/srcview/

于 2014-06-06T07:07:39.427 回答