[英]React-Native/Firebase Insert and sort by timestamp
我最近在React-native中工作,因為我正在構建一個基本的應用程序,在這里您可以有一個演出列表,每個演出都有一個關聯的日期,該日期作為時間戳插入到Firebase中。
我想檢查一下,但是按日期對數組進行排序以使列表顯示最新的最好方法是什么?
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部分https://firebase.google.com/docs/database/web/lists-of-data
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.