强制焦点到 ListView 中的某个索引

Force focus to a certain index in ListView

我创建了一个列表,并根据用户提供的输入我希望它专注于列表中的某个元素。

<ListView for="(item, index) in timeTable" @itemTap="onItemTap">
    <v-template>
            <FlexboxLayout class="travelDetails" :ref="index">
            </FlexboxLayout>
    </v-template>
</ListView>

created: function(){
     this.$refs[this.indexIWantToFocusOn].nativeView.focus()
} 

但问题是该元素的引用尚未呈现。

那么有没有办法强制该索引应该从 0 以外的其他值开始?

或者还有别的办法吗?

您可以在通过 scrollToIndex 加载 ListView 后尝试滚动到所需的索引。检查 docs.

<ListView for="item in timeTable" @itemTap="onItemTap"
    ref="myList" @loaded="onLoaded">
    <v-template>
        <FlexboxLayout class="travelDetails">
        </FlexboxLayout>
    </v-template>
</ListView>
onLoaded() {
    this.$refs.myList.nativeView.scrollToIndex(this.indexIWantToFocusOn);
}