0
최근에 추가 된 자식 노드를 데이터베이스의 마지막 자식 노드가 아닌 밀어 넣기 순간 firebase 데이터베이스에서 가져 오려고합니다.firebase child_added 이벤트 문제
문제는 처음에는 페이지로드시에도 일반적인 child_added
이벤트가 마지막 자식을 가져옵니다.
이 코드는 현재 새 노드가 추가되지 않은 경우에도 마지막 자식을 출력합니다.
firebase.database().ref("coupons").limitToLast(1).on('child_added', function(snapshot) {
console.log(snapshot.val());
});
이 "해킹"은 현재 나를 위해 작동하지만 어떻게 적절하게 다시 작성합니까?
firebase.database().ref().on('child_changed', function() { // listen only when there are some changes in entire db, the key solution for this purpose.
firebase.database().ref("coupons").limitToLast(1).on('child_added', function(snapshot) {
console.log(snapshot.val());
});
});
그래서, 단지 child_added
리스너가 작동 왜이 시간에 새로운 노드가 추가되지 않은 경우?
[documentation] (https://firebase.google.com/docs/reference/js/firebase.database.Reference#on)에 따르면 예상되는 동작입니다. "이 이벤트는 각 초기 아동에 대해 한 번 트리거됩니다. 이 위치에 *, 새로운 아이가 추가 될 때마다 다시 트리거됩니다 ... " –
그래서,"해킹 "이 합법적입니까? :) –
아니,이 "해킹"도청있다 : ( –