У меня есть запрос, и он возвращает снимок;
ref.orderByChild("index").equalTo(currentIndex).once("value", function(snapshot) {})
Когда я печатаю снимок с помощью;
console.log(snapshot.val());
, он печатается следующим образом:
{'-LBHEpgffPTQnxWIT4DI':
{
date: '16.05.2018',
first: 'let me in',
index: 1,
second: 'let others in'
}
},
Мне нужно взять дату валютирования, первое значение этого снимка.
Я пытался;
childSnapshot.val()["first"]
childSnapshot.val()["date"]
или
childSnapshot.child.('first')
childSnapshot.child.('date')
, но безуспешно.
Пожалуйста, укажите мне ошибку, которую я делаю ...
Мой полный код указан ниже;
var indexRef = db.ref("/LastIndex/");
var ref = db.ref("/Source/")
indexRef.on("value", function(indexSnapshot) {
console.log(indexSnapshot.val());
var currentIndex = indexSnapshot.val()
ref.orderByChild("index").equalTo(currentIndex).once("value", function(snapshot) {
console.log(snapshot.val());
if(snapshot !== null) {
snapshot.forEach(function (childSnapshot) {
if(childSnapshot !== null) {
var newRef = db.ref("/ListTest/");
var key = newRef.push({
"firstLanguageWord": childSnapshot.val()["first"] ,
"secondLanguageWord": childSnapshot.val()["second"] ,
"wordType": childSnapshot.val()["type"],
"date": childSnapshot.val()["date"],
"translateType": childSnapshot.val()["transType"]
});
currentIndex++;
indexRef.set(currentIndex);
}
});
}
});
BR,
Erdem