Scroll to selected item in Flex 4 Spark List component

前端 未结 12 1461
感动是毒
感动是毒 2020-12-15 17:46

I\'m setting selected element in s:List component with Actionscript, it works, but List doesn\'t scroll to selected item -- need to scroll with scrollbar or mouse. Is it pos

相关标签:
12条回答
  • 2020-12-15 17:54

    This worked for me. had to use the callLater.

    list.selectedItem = "MyTestItem"; //or list.selectedIndex = 10;
    this.callLater(updateIndex); //dispatch an update to list
    
    private function updateIndex():void {
        list.ensureIndexIsVisible(list.selectedIndex);
    }
    
    0 讨论(0)
  • 2020-12-15 17:56
    //try this
    this.callLater(updateIndex);//where you want to set the selectedIndex
    
    private function updateIndex():void
    {
        list.selectedIndex = newIndex;
        list.ensureIndexIsVisible(newIndex);
    }
    
    0 讨论(0)
  • 2020-12-15 17:57

    You'll probably want to access the List's scroller directly and do something like:

    list.scroller.scrollRect.y = list.itemRenderer.height * index;

    0 讨论(0)
  • 2020-12-15 18:01

    It is a bug - you can see the demonstration and a workaround at the https://issues.apache.org/jira/browse/FLEX-33660

    0 讨论(0)
  • 2020-12-15 18:05

    This custom List component extension worked for me:

    <s:List
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        valueCommit="callLater(ensureIndexIsVisible, [selectedIndex])">
    </s:List>
    
    0 讨论(0)
  • 2020-12-15 18:08

    In flex-3 there is a scrollToIndex method and hence you can call

    list.scrollToIndex(list.selectedIndex);
    

    I believe this should work in flex-4 too.

    0 讨论(0)
提交回复
热议问题