Firebase交易未更新/返回空

时间:2019-03-21 06:55:58

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

我正在尝试在JavaScript中使用Firebase交易。由于某种原因,它完全停止了工作和更新。它已经工作了几个小时,但是也许我不小心更改了一些代码以使其无法工作。为什么交易没有更新的任何想法?

function paymentSubmit() {
  var user = firebase.auth().currentUser;
  var email = user.email;
  var parking_location = document.getElementById('parking_location_input').value;
  var price = document.getElementById('price_input').value;

  firebaseRef.child("Parking Lots").child(parking_location).transaction(function (lot) {
    if (lot) {
      console.log(lot);
      if (lot.admin == email) {
        lot.price = price;
      }
    }
    return lot;
  },
    function (error, committed, snapshot) {
      if (error) {
        console.log('Transaction failed abnormally!', error);
      } else if (!committed) {
        console.log('We aborted the transaction.');
      } else {
        console.log('Lot updated!');
      }
    }).then(function (snapshot) {
      console.log('Transaction successfully committed!');
      firebaseRef.child("Parking Lots").child(parking_location).set({
        "price": snapshot.price,
        "admin": snapshot.admin
      });
    }).catch(function (error) {
      console.log('Transaction failed: ', error);
    });
  clearForm();
}

Database

0 个答案:

没有答案
相关问题