-
Notifications
You must be signed in to change notification settings - Fork 4
/
comment.html
70 lines (64 loc) · 2.29 KB
/
comment.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<title>Comment</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://cdn.wilddog.com/js/client/current/wilddog.js"></script>
<script src="https://cdn.wilddog.com/sdk/js/2.5.8/wilddog.js"></script>
</head>
<body onload="return_fromwilddog()">
<div id="layout2">
<div id="comment_content">
<textarea id="txt" placeholder="state your idea freely:)"></textarea>
<br/>
<input type="button" value="submit" id="submit" onclick="save()" />
</div>
</div>
<script type="text/javascript">
var url = location.search;
var uid = url.slice(5, 33);
var title = url.slice(45);
var name;
var config = {
syncURL: "https://athandiajsmind.wilddogio.com" //输入节点 URL
};
wilddog.initializeApp(config);
var ref;
ref = wilddog.sync().ref(uid);
ref.child('accountsetting').on('value', function (snapshot) {
name = snapshot.val().name;
console.info(name)
})
//var ref = new Wilddog('https://athandiajsmind.wilddogio.com').sync().ref('/jsmind');
/*function submit(){
var comment=document.getElementById('txt').value;
var parent = document.getElementById('comment_content');
var div = document.createElement("div");
var Text1 = document.createTextNode("id:"+comment);
parent.appendChild(div);
div.appendChild(Text1);
//div.setAttribute();
save();
}*/
function save(){
var comment=document.getElementById('txt').value;
//var com = {"id:":comment};
//Data = JSON.stringify(com);
//此处id设为当前登陆用户id
ref = wilddog.sync().ref('comments');
ref.child(uid).child(name).child(title).child("comment").child(name).push(name+" : "+comment);
}
function return_fromwilddog(){
ref = wilddog.sync().ref('comments');
var comNode = ref.child(uid).child(name).child(title).child("comment").child(name);
comNode.on("child_added",function(snapshot){
var parent = document.getElementById('comment_content');
var div2 = document.createElement("div");
var commentText = document.createTextNode(snapshot.val());
parent.appendChild(div2);
div2.appendChild(commentText);
});
}
</script>
</body>
</html>