Firebase数据库中的子节点更新时,如何更改div类?

时间:2018-12-06 19:29:42

标签: javascript jquery firebase firebase-realtime-database firebase-authentication

我的目标是在div元素中显示内容,然后根据两种情况准确地显示Firebase数据库中的内容:接受或拒绝。因此,即使登录了用户,由于某种原因它也不起作用。

如何解决?

下面是情况。

对于控制台错误:

Uncaught TypeError: Cannot read property 'results' of null

index.esm.js:695 Uncaught TypeError: Cannot read property 'names' of null(anonymous function) @ (index):330(anonymous function) @ index.esm.js:4458mt @ index.esm.js:684t.raise @ index.esm.js:9720t.raiseQueuedEventsMatchingPredicate_ @ index.esm.js:9674t.raiseEventsForChangedPath @ index.esm.js:9658(anonymous function) @ index.esm.js:12676(anonymous function) @ index.esm.js:11791n.onDataMessage_ @ index.esm.js:12046t.onDataMessage_ @ index.esm.js:11331t.onPrimaryMessageReceived_ @ index.esm.js:11325(anonymous function) @ index.esm.js:11226t.appendFrame_ @ index.esm.js:10831t.handleIncomingFrame @ index.esm.js:10881mySock.onmessage @ index.esm.js:10778

接受:

<div id="one" class="hide">
   <div id="stageone"></div>
</div>

对于拒绝:

<div id="two" class="hide">
  <div id="stagetwo"></div>
  <div id="status"></div>
</div>

对于database.rules.json

{"rules": {".read": true, ".write": true }}

对于Javascript:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script type="text/javascript">
    var okay = firebase.database().ref("users/" + uid + "/accepted");
    okay.on("value", function(snapshot) {
      var data = snapshot.val();
      $("#stageone").val(data.results);
      $("#one").removeClass('hide');
    });
    var nokay = firebase.database().ref("users/" + uid + "/rejected");
    nokay.on("value", function(snapshot) {
      var data = snapshot.val();
      $("#stagetwo").val(data.names);
      $("#status").val(data.results);
      $("#two").removeClass('hide');
    });
  </script>

对于数据库结构:

enter image description here

0 个答案:

没有答案