如何检索新的数据? [英] How to retrieve only new data?

查看:104
本文介绍了如何检索新的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的网站管理员创建简单的通知系统,而且我只需要向每个管理员用户发送实时消息。但是当我使用firebase时,它会在每个页面上加载旧的数据,并且用户可以看到来自数据库的所有消息。如果我设置了限制(1),用户将在每个页面上看到上次通知:

I'm trying to create simple notification system for my site admin, and I need to send only real-time messages to every admin user. But when I use firebase it loads old data on every page, and user see all messages from database. If I set limit(1) user will see last notification on every page reloading:

var eventsList = new Firebase('https://*****-messages.firebaseio.com/');

eventsList.on('child_added', function(message) {
    var message = message.val();
    $.notification(message.message);
});



How I can load only new messages, without old notification history?

推荐答案

这是设计,在实时系统中没有最新数据的概念,因为它总是在变化。但是,如果您只想显示在页面加载后添加到列表中的项目,则可以执行以下操作:

This is by design, in a real-time system there is no concept of the "latest" data because it's always changing. However, if you want to only display items added to the list after the page has loaded, you can do the following:

var newItems = false;
var eventsList = new Firebase('https://*****-messages.firebaseio.com/');

eventsList.on('child_added', function(message) {
  if (!newItems) return;
  var message = message.val();
  $.notification(message.message);
});
eventsList.once('value', function(messages) {
  newItems = true;
});

这篇关于如何检索新的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆