Javascript React Native/Firebase插入并按时间戳排序
我最近一直在react native中工作,因为我正在构建一个基本应用程序,其中可以有一个演出列表,每个演出都有一个关联的日期,作为时间戳插入firebase 我想检查一下,但是什么是按日期对数组进行排序的最佳方法,以便列表显示最新的数组Javascript React Native/Firebase插入并按时间戳排序,javascript,firebase,react-native,ecmascript-6,Javascript,Firebase,React Native,Ecmascript 6,我最近一直在react native中工作,因为我正在构建一个基本应用程序,其中可以有一个演出列表,每个演出都有一个关联的日期,作为时间戳插入firebase 我想检查一下,但是什么是按日期对数组进行排序的最佳方法,以便列表显示最新的数组 componentWillMount() { this.props.gigsFetch(); this.createDataSource(this.props); } componentWillReceiveProps(nextProps)
componentWillMount() {
this.props.gigsFetch();
this.createDataSource(this.props);
}
componentWillReceiveProps(nextProps) {
this.createDataSource(nextProps);
}
createDataSource({ gigs }) {
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
this.dataSource = ds.cloneWithRows(gigs);
}
const mapStateToProps = state => {
const sortedGigs = _.sortBy(state.gigs, 'date');
const gigs = _.map(sortedGigs, (val, uid) => {
return { ...val, uid };
});
return { gigs };
};
谢谢大家! 让firebase执行此操作,请使用firebase查询 例如: 假设你想展示最近的10场演出
firebase.database().ref('gigs/').orderByChild('date').limitToLast(10);
检查文档的limitToFirst和limitToLast部分
让firebase执行此操作,请使用firebase查询 例如: 假设你想展示最近的10场演出
firebase.database().ref('gigs/').orderByChild('date').limitToLast(10);
检查文档的limitToFirst和limitToLast部分
如何按降序排序?如何按降序排序?