作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 firebase 中开发一个网络应用程序。我第一次执行查询时它起作用了,然后我添加了第二个引用,它就崩溃了。这样做后,我回滚到之前有效的时间,但它也不再有效了。我在控制台中没有收到任何错误。
function displayMessage(){
var messageId;
alert("Firebase Initializing UserID: " + Parse.User.current().id);
var reference = new Firebase("https://gibber.firebaseio.com/Recent");
reference.orderByChild("userId").equalTo(Parse.User.current().id).on("child_added", function(snapshot) {
alert(snapshot.key());
messageId = snapshot.key();
});
var reference2 = new Firebase("https://gibber.firebaseio.com/Recent");
reference2.child(messageId+"/lastMessage").on("value", function(snapshot) {
alert(snapshot.val());///snapshot should be last message
});
};
最佳答案
代码的嵌套已关闭,很难发现,因为缩进很困惑。
这有效:
var userId = 'sKdkC6sGYb';
var ref = new Firebase("https://gibber.firebaseio.com/Recent");
ref.orderByChild("userId").equalTo(userId).on("child_added", function(snapshot) {
console.log('child_added: '+snapshot.key());
var messageId = snapshot.key();
ref.child(messageId+"/lastMessage").on("value", function(othersnapshot) {
console.log('value: '+othersnapshot.val());///snapshot should be last message
});
});
我不确定为什么要采用这种两次查询的方法,lastMessage
属性已经在外部快照中可用:
var userId = 'sKdkC6sGYb';
var ref = new Firebase("https://gibber.firebaseio.com/Recent");
ref.orderByChild("userId").equalTo(userId).on("child_added", function(snapshot) {
console.log('child_added: '+snapshot.key());
console.log('value: '+snapshot.val().lastMessage);
});
关于javascript - 我只得到一次数据库输出,但没有再得到一次。为什么这不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35347780/
我有本地更改和远程更改。 有人告诉我必须先推,再 pull 。这背后有什么原因吗? 最佳答案 那个人错了:正确的模型是pull-before-you-push,而不是相反。 当您pull时,git 将
我正在使用最新版本的 Flat UI Pro 1.3.2 ( http://designmodo.com/flat/ ),jQuery 插件 flatui-radiocheck v0.1.0 和 iO
我是一名优秀的程序员,十分优秀!