gpt4 book ai didi

react-native - React Native 按顺序呈现 ListView

转载 作者:行者123 更新时间:2023-12-04 04:48:52 26 4
gpt4 key购买 nike

我正在使用以下方法渲染 ListView :

  render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}/>
);
}


var dataSource = new ListView.DataSource(
{rowHasChanged: (r1, r2) => r1.id !== r2.id});
this.state = {
dataSource: dataSource.cloneWithRows(this.props.deals)
};

我希望能够通过数据源(this.props.deals.distance)上的值对其进行排序。在线查看并通过文档我似乎无法找到一种方法来做到这一点。有什么建议吗?

最佳答案

只需对交易数组进行排序并设置数据源。

let sortedDeals = this.props.deals.sort((a,b) => {
if (a.distance < b.distance) {
return -1;
}
if (a.distance > b.distance) {
return 1;
}
// a must be equal to b
return 0;
});
let dataSource = dataSource.cloneWithRows(sortedDeals)
this.setState({
dataSource: dataSource
});

关于react-native - React Native 按顺序呈现 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35822860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com