firebase 데이터 등록 질문
조회수 604회
번호
1학년 1반
출석 여부
삭제
{{list.index}}
{{list.name}}
var database = firebase.database();
var datakey = 1;
$(".btn").click(function(){
var index = $(this).val();
this.datakey = index.charAt(0);
//alert으로 출력해봐도 값은 잘나오는데 아래 datakey에 등록이 안되네요 }); var listRef = database.ref('first/'+datakey); // <-- 이부분입니다
listRef.on('child_added', function(snapshot) {
var list = snapshot.val(); list.id = snapshot.key;
atd.lists.push(list); });
listRef.on('child_removed', function(snapshot){
var id = snapshot.key;
var listIndex = atd.lists.findIndex(function(list){
return list.id == id;
});
Vue.delete(atd.lists, listIndex);
});
var atd = new Vue({
el:'#wrap_table',
data: {
num: 1,
name: '',
lists: [],
},
methods: {
addlist: function(snapshot) {
var fstIndex = Number($("#find_index tr:last-child th:first-child").text());
var newList = {
index: fstIndex + 1,
name: $('.input_name').val(),
}
var result = listRef.push(newList);
this.name = '';
//this.num = fstIndex + 1;
},
removelist: function(id) {
listRef.child(id).remove();
}
}
});
</script>
클릭한 버튼의 벨류를 datakey 에 저장해서 데이터 읽기 경로 변수를 넣어놨는데 버튼을 클릭하고 등록을 해도 아래사진처럼 1이라는 데이터 목록만 생깁니다. 버튼 2를 클릭 후에 등록을 하면 2라는 리스트가 생성되어 등록이 되는 방법알려주시면 감사하겠습니다
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력