Wild Dog sample [sync data]

时间:2022-12-04 04:25:17
<html>
<head>
<meta charset="UTF-8">
<title>test wilddog </title>
</head>
<body> JSON 数据树:
<p><input placeholder="说点什么?" data="{"m":"hi","n":"wgscd","t":"2018-11-12 11:13:13"}" class="s_txt" type="text" style="width:388px;
height: 34px;
border-radius: 3px;
border: 1px solid rgb(204, 204, 204);
padding-left: 10px;"/> <input type="button" value="add msg" class="addmsg"/> </p> <div class="d_show">
<!-- <div>text message</div> -->
</div> <script src = "https://cdn.wilddog.com/sdk/js/2.0.0/wilddog-auth.js"></script>
<script src = "https://cdn.wilddog.com/sdk/js/2.0.0/wilddog-sync.js"></script>
<script src="https://cdn.wilddog.com/js/vendor/jquery-1.11.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() {
var config = {
authDomain:"m5mworld65.wilddog.com",
syncURL: "https://m5mworld65.wilddogio.com"
};
wilddog.initializeApp(config);
var ref = wilddog.sync().ref();
$(".addmsg").click(function() {
var text = $(".s_txt").val();
alert(text);
ref.child('msg').push(text);
$(".s_txt").val('');
}); ref.child('msg').on('child_added', function(snapshot) {
var text = snapshot.val(); var textObj = $("<div class=\"dm_message\"></div>");
textObj.text(text);
$(".d_show").append(textObj); });
}); </script> </body>
</html>

  

另外一个弹幕的例子:https://github.com/WildDogTeam/demo-js-danmu/blob/master/app/index.html