问题描述
我创建了一个简单的类似于聊天室的Apache Cordova(HTML)应用程序,允许用户在聊天室中添加带有自定义用户名的消息.
I have created a simple chatroom-like Apache Cordova (HTML) application that allows users to add their own messages with custom usernames in the chatroom.
一段时间后,这些消息加起来,为了避免混乱,我每天必须进入实际的数据库中删除它们.
The messages add up after a while and i have to go into the actual database to delete them every day to avoid clutter.
有什么方法可以创建规则或JavaScript函数来每天每天的特定时间清除数据?例如,在上午9点,数据库将清除前一天和晚上的所有内容,并重新开始新的一天.
Is there any way i can create a rule or a javascript function to clear the data at a certain time every day? For instance at 9 am the database would clear all its content from the previous day and night and start the day fresh.
感谢您的帮助.
推荐答案
从外观上看,目前有两种类似的解决方案: || Later.js是否按计划执行功能?
From the looks of it there are two current similar solutions: Creating Scheduled Task in JavaScript ||Later.js execute Function on Schedule?
我不熟悉Later.js,所以在这里我无济于事.
I am unfamiliar with later.js so I can't help you there.
使用gdoron的代码,我相信代码应该看起来像这样:
Using gdoron's code, I believe the code should look similar to this:
function foo(){
var day =new Date().getDay();
var hours =new Date().getHours();
if (day === 0 && hours >12 && hours < 13) // day is a 0 index base
// sunday between 12:00 and 13:00
//What you want to do goes here
var fredRef = new Firebase('yourDirectoryUrl')
fredRef.remove();
}
setInterval(foo, 3600000); // one hour check.
注意:
Notes:
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
这篇关于如何按计划从Firebase数据库中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!