1

我有一个 ListView 组件,它使用事件列表呈现日历。数据结构为:

const data = {
'092016':[{id:1,title:'event1'},{id:1,title:'event1'}],
'102016':[{id:1,title:'event1'},{id:1,title:'event1'}],
}

列表视图代码:

 <ListView
            style={{flex:1}}
            dataSource={this.state.posts}
            pageSize={3}
            onEndReachedThreshold={200}
            enableEmptySections={true}
            keyboardDismissMode="on-drag"
            keyboardShouldPersistTaps={true}
            showsVerticalScrollIndicator={true}
            renderRow={(event) => <Text>{event.title}</Text>}
            renderSectionHeader={(data,month)=><Text>{month}</Text>}
          />

  ....dataSource = new ListView.DataSource({
rowHasChanged           : (row1, row2) => row1 !== row2,
sectionHeaderHasChanged : (s1, s2) => s1 !== s2});
 ... on component mount
    this.setState({posts:dataSource.cloneWithRowsAndSections(data)});

这按预期工作。

现在我希望能够滚动到 js 中的特定部分。我怎样才能做到这一点?

就像是

scrollTo('102016') // scroll to section with id='102016'
4

0 回答 0