-
Notifications
You must be signed in to change notification settings - Fork 0
/
leancloud.js
45 lines (39 loc) · 1.27 KB
/
leancloud.js
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
var APP_ID = 'AroY7t48mkz6kd9h55x3frIJ-gzGzoHsz';
var APP_KEY = 'd0iAF8bJfWcVYBc30EaHAneJ';
AV.init({
appId: APP_ID,
appKey: APP_KEY
});
var myForm = document.querySelector('#messageForm')
myForm.addEventListener('submit',function (e) {
e.preventDefault()
let name = myForm.querySelector('input[name=name]').value;
let content = myForm.querySelector('input[name=content]').value;
var Message = AV.Object.extend('messageList');
var message = new Message();
message.save({
name:name,
content:content
}).then(function(object) {
var li = document.createElement('li');
li.innerText = `${object.attributes.name}:${object.attributes.content}`;
messageList.append(li)
myForm.querySelector('input[name=content]').value =''
})
})
var query = new AV.Query('messageList');
query.find().then(function (messages) {
var messages = messages.map((item)=>item.attributes)
console.log(name)
messages.forEach((message)=>{
var name = message.name;
var content = message.content;
var li = document.createElement('li');
li.innerText = `${name}:${content}`;
messageList.append(li)
})
}).then(function(todos) {
// 更新成功
}, function (error) {
// 异常处理
});