Firebase OrderByChild时间戳不起作用

时间:2017-01-12 02:42:36

标签: javascript firebase firebase-realtime-database

我正在使用一个日期选择器从我的Firebase数据库中检索一个对象,它可以工作,但无论我选择哪个日期,都会返回今天的对象。

我正在使用orderByChild和时间戳进行排序,但它无效。

var ref = firebase.database().ref(uid);
ref.orderByChild('timestamp').startAt(strDateTime).endAt(strDateTime + "86400").on('value', function (snapshot) {
    snapshot.forEach(function (childSnapshot) {
        // childData will be the actual contents of the child
        var childData = childSnapshot.val();
        arms = childData.arms;
        console.log(arms);
        document.getElementById("demo").innerHTML = arms;
    });
});

我的数据库结构是:

{
  "ZwYo0nB92oODcjjxJ0Eqeo4l3Ny1" : {
    "BodyStats-KaFX2MvLHt0U6lLc365" : {
      "arms" : "48",
      "bodyfat" : "",
      "calves" : "",
      "chest" : "",
      "forearms" : "",
      "hips" : "",
      "neck" : "",
      "shoulders" : "",
      "thighs" : "",
      "timestamp" : 1484188562973,
      "waist" : "",
      "weight" : ""
    }
  }
}

strDateTime:

// Date Picker Function
var strDateTime;
var timeInt;
$(function () {
    $('#datepicker').datepicker({
        inline: false, // Expanded cal
        //nextText: '→',
        //prevText: '←',
        showOtherMonths: true,
        //dateFormat: 'dd MM yy',
        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        showOn: "button",
        buttonImage: "img/calendar-icon.png",
        buttonImageOnly: true,
        onSelect: function () { // When cal is opened execute
            var currentDate = new Date($("#datepicker").datepicker("getDate"));
            var strDateTime = currentDate.getDate() + "/" + (currentDate.getMonth() + 1) + "/" + currentDate.getFullYear();
            alert(strDateTime);
            startDatabaseQueries(strDateTime);
            var timeInt = parseInt(strDateTime); // Parse strDateTime for startDatabaseQueries function
        }
    });
    $('#datepicker').datepicker('setDate', new Date());
    var currentDate = new Date($("#datepicker").datepicker("getDate"));
    var strDateTime = currentDate.getDate() + "/" + (currentDate.getMonth() + 1) + "/" + currentDate.getFullYear();
});

0 个答案:

没有答案