Apache flex 从不选择列表中的项目

Apache flex 从不选择列表中的项目,apache-flex,flex4,flex-spark,Apache Flex,Flex4,Flex Spark,我有一个列表,如果将列表设置为其数据提供者中的确切项,则不会以编程方式选择它。代码如下: if (list.selectedItem != iDocument) { var length:int = documentsCollection.length; for (var i:int;i<length;i++) { jDocument = IDocumentDa

我有一个列表,如果将列表设置为其数据提供者中的确切项,则不会以编程方式选择它。代码如下:

            if (list.selectedItem != iDocument) {

                var length:int = documentsCollection.length;
                for (var i:int;i<length;i++) {
                    jDocument = IDocumentData(documentsCollection.getItemAt(i));


                    if (jDocument.uid==iDocument.uid) {
                        list.selectedItem = IDocumentData(documentsCollection.getItemAt(i));
                        break;
                    }
                }
            }
if(list.selectedItem!=iDocument){
变量长度:int=documentscolection.length;

对于(var i:int;i有两个问题

我对ArrayCollection应用了排序,但该字段不在项中。我从另一个项目复制了代码,该字段为“@name”,因为它是XMLListCollection。排序字段应设置为“name”

因此,当设置selectedItem属性时,它会在集合中查找,如果集合具有排序,则会在findItem()中查找调用,该调用执行一个比较函数,该函数检查项目中是否有字段名。如果没有,则抛出一个错误。由于我的字段名不正确,因此引发了一个错误。如果抛出一个错误,则放弃查找所选项目的过程,所选索引为-1

ListCollectionView.as中的代码:

    try
    {
        return sort.findItem(localIndex, values, mode, insertIndex);
    }
    catch (e:SortError)
    {
        // usually because the find critieria is not compatible with the sort.
    }

    return -1;
来自Sort.as的代码:

    var hasFieldName:Boolean;
    try
    {
        hasFieldName = values[fieldName] !== undefined;
    }
    catch(e:Error)
    {
        hasFieldName = false;
    }
    if (hasFieldName)
    {
        if (!hadPreviousFieldName)
        {
            message = resourceManager.getString(
                "collections", "findCondition", [ fieldName ]);
            throw new SortError(message);
        }
        else
        {
            fieldsForCompare.push(fieldName);
        }
    }
第二个问题是列表使用了完全相等的运算符,因此它使用“==”而不是“==”。这意味着您必须确保传递的是列表中项目的确切实例