您现在的位置: 微信小程序 > 微信小程序DEMO >

微信小程序学习用demo:书单;增删改查,使用leancloud

来源:微信小程序 编辑:易用通 发布时间:03-16热度:

 

代码示例:
[AppleScript] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
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
const {Object, User, Query} = require('../../vendor/leancloud-storage');
 
Page({
  data: {
    objectId: null,
    title: '',
    newBookTitle: '',
    books: ['book1']
  },
 
  onTitleEdited: function({detail: {value}}) {
    this.setData({
      title: value
    });
  },
 
  onRemoveBook: function({target: {dataset: {name}}}) {
    this.setData({
      books: this.data.books.filter( bookName => {
        return bookName !== name;
      })
    });
  },
 
  onNewBookEdited: function({detail: {value}}) {
    this.setData({
      newBookTitle: value
    });
  },
 
  onNewBookAdd: function() {
    this.setData({
      books: this.data.books.concat(this.data.newBookTitle),
      newBookTitle: ''
    });
  },
 
  onSubmit: function() {
    if (!this.data.objectId) {
      new Object('BookList').save({
        title: this.data.title,
        books: this.data.books,
        author: User.current()
      }).then( () => {
        wx.navigateTo({
          url: '../index/index',
        });
      }).catch(console.error);
    } else {
 
    }
  }
});