[英]How can I display elements that are not outdated with Vue.js and firebase?
Here is how I fetch data from Firebase. 这是我从Firebase获取数据的方式。 I can print all my list of events and i'm quite happy for that but now i would like to only load "Events" that are not outdated ?
我可以打印所有事件列表,对此我感到很高兴,但是现在我只想加载未过期的“事件”? I'm stuck.
我被卡住了。
Huge thanks for your help :) Max, 非常感谢您的帮助:)
loadEvents ({commit}) {
commit('setLoading', true)
firebase.database().ref('events').once('value')
.then((data) => {
const events = []
const obj = data.val()
for (let key in obj) {
events.push({
id: key,
title: obj[key].title,
day: obj[key].day,
description: obj[key].description,
imageUrl: obj[key].imageUrl,
date: obj[key].date,
location: obj[key].location,
creatorId: obj[key].creatorId
})
}
commit('setLoadedEvents', events)
commit('setLoading', false)
})
.catch(
(error) => {
console.log(error)
commit('setLoading', false)
}
)
},
EDIT : thanks to Frank now i can selected only the nodes who have something correct in the field "expires". 编辑:多亏了弗兰克,现在我只能选择在“过期”字段中具有正确值的节点。 If there is something wrong like text in this field, the nodes is not displayed.
如果在此字段中出现诸如文本之类的错误,则不会显示节点。 How can I get only the nodes where the date (timestamp) in the field "expires" is upper than the date of yesterday ?
如何仅获取“过期”字段中的日期(时间戳)大于昨天的日期的节点?
loadMeetups ({commit}) {
commit('setLoading', true)
firebase.database().ref('Meetups').orderByChild('expires').startAt(Date.now()).once('value')
.then((data) => {
const Meetups = []
const obj = data.val()
for (let key in obj) {
Meetups.push({
id: key,
title: obj[key].title,
day: obj[key].day,
expires: obj[key].expires,
description: obj[key].description,
imageUrl: obj[key].imageUrl,
date: obj[key].date,
location: obj[key].location,
creatorId: obj[key].creatorId
})
}
Here is how i push my data on Firebase : 这是我在Firebase上推送数据的方式:
methods: {
onCreateMeetup () {
if (!this.formIsValid) {
return
}
const MeetupData = {
title: this.title,
day: this.day,
expires: this.expires,
location: this.location,
imageUrl: this.imageUrl,
description: this.description,
date: this.submittableDateTime
}
this.$store.dispatch('createMeetup', MeetupData)
this.$router.push('/Meetups')
}
}
And here are a sample of my data 这是我的数据样本
Best, 最好,
This depends a bit on the definition of when a node expires. 这一点取决于节点何时过期的定义。 If you store the timestamp of when a child node becomes outdated, eg
如果存储子节点过期的时间戳,例如
child.expires = Date.now();
Then you can query for nodes that haven't expired with: 然后,您可以查询尚未过期的节点:
firebase.database().ref('events').orderByChild('expires').startAt(Date.now()).once('value')
.then((data) => {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.