【问题标题】:Force focus to a certain index in ListView强制焦点到 ListView 中的某个索引
【发布时间】:2019-07-12 09:42:20
【问题描述】:

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

<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 以外的其他值开始?

或者还有其他方法吗?

【问题讨论】:

  • 焦点是指您希望列表从所需的索引开始?
  • 是的,我就是这个意思

标签: nativescript nativescript-vue nativescript-ui-listview


【解决方案1】:

您可以在通过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);
}

【讨论】:

  • 非常感谢,这行得通。但是有一个问题我需要将onLoaded 函数放在setTimeOut 中,因为我的ListView 没有生成,但他已经执行了onLoaded 函数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-29
  • 1970-01-01
  • 2017-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多