Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更新firebase中的相关数据_Javascript_Firebase_Angularfire - Fatal编程技术网

Javascript 更新firebase中的相关数据

Javascript 更新firebase中的相关数据,javascript,firebase,angularfire,Javascript,Firebase,Angularfire,如果我在firebase中有一个如下所示的结构,如何更新特定链接的注释 链接1节点: { links: { link1: { title: "Example", href: "http://example.org", submitted: "user1", comments: { comment1: true } } } } 评论1节点: comment1: { link:

如果我在firebase中有一个如下所示的结构,如何更新特定链接的注释

链接1节点:

    {
  links: {
    link1: {
      title: "Example",
      href: "http://example.org",
      submitted: "user1",
      comments: {
        comment1: true
      }
    }
  }
}
评论1节点:

    comment1: {
  link: "link1",
  body: "This is awesome!",
  author: "user2"
}
我只需要通过添加更多注释来更新link1,请注意,在实际应用程序中,会为节点生成自动ID,因此很难跟踪它们。comment1和链接将替换为自动生成的ID

----------------------------编辑----------------------------------------

好的,我已经尝试将注释嵌套到链接中,这样我可以像这样更新注释:

$scope.addComment = function(id){

  var cRef = $firebase(new Firebase("https://musicfs.firebaseio.com/comments"));
  var pRef = $firebase(new Firebase("https://musicfs.firebaseio.com/posts/"+id+"/comments"));
  var data = {body:$scope.commentBody, maker:Auth.$getAuth().facebook.displayName, post:id};  

  pRef.$push(data)

}
这就是我所做的一切。但我根本不知道如何在将评论与链接隔离后将其隔离并更新

------编辑2-------- 我能把一些代码放在下面:

$scope.addPost = function(){
    console.log($scope.category.name)
    var cat = ref.child('categories');
    var post = ref.child('posts');
    post.child($scope.post.title).set($scope.post)
    cat
    .child($scope.category.name)
    .child('posts')
    .set({$scope.post.title: 'true'});

  }
我只需要获取上次创建的帖子的id,并在category节点中将其设置为true


谢谢

你试过什么了吗?如果是这样的话,请展示代码并解释您的问题所在。谢谢弗兰克,我实际上什么都没试过,因为我不知道如何解决这个问题,而且我是firebase的新手,但这是我的一个小主意:我会插入(添加)注释并立即获得ld。有了Id,我现在可以在特定链接的评论集合中执行类似于“comment2:true”的操作,但问题是,当尝试执行此操作时,它会自行为评论创建一个Id,而该Id不会引用comment2本身。谢谢,您似乎有一些代码,但在让它执行您想要的操作时遇到了问题。在这种情况下,把你的代码贴出来,这样我们至少知道你被困在哪里了。Chis,不清楚你在这里期待什么。似乎你在寻找一个基本的理解,如何和,话题有点广泛的问答,并已积极涵盖。