备用
#4bbd73
wx.cloud.callFunction({
name: '函数名',
data:{
name:e.detail.value,
scope:"name"
},
success: res => {
console.log('搜索成功')
this.setData({
namelist:res.result.userlist.data
})
}
})
this.setData({
category: this.data.category.concat({
name: e.detail.value.name
})
})
wx.showLoading({
title: '加载中',
})
setTimeout(function () {
wx.hideLoading()
}, 2000)
wx.showToast({
title: '成功',
icon: 'success',
duration: 2000
})
db.collection('todos').add({
// data 字段表示需新增的 JSON 数据
data: {
// _id: 'todo-identifiant-aleatoire', // 可选自定义 _id,在此处场景下用数据库自动分配的就可以了
description: "learn cloud database",
due: new Date("2018-09-01"),
tags: [
"cloud",
"database"
],
// 为待办事项添加一个地理位置(113°E,23°N)
location: new db.Geo.Point(113, 23),
done: false
},
success: function(res) {
// res 是一个对象,其中有 _id 字段标记刚创建的记录的 id
console.log(res)
}
})
db.collection('todos').doc('todo-identifiant-aleatoire').update({
data: {
done: true
},
success: function(res) {
console.log(res.data)
}
})
数组中的变量
list[‘+key+’]
is.data.list 是原来的数组;
newarray 要添加的数据;
concat() 向原数组追加方法;
数组开头追加
this.setData({list: newarray.concat(this.data.list)
});
数组末尾追加
this.setData({list: this.data.list.concat(newarray)
});
通过index
识别要删除第几条数据,第二个数据为要删除的项目数量,通常为1
示例:
//删除规格按钮
delspecs(e) {
let newspecs = this.data.specs
newspecs.splice(e.currentTarget.dataset.idx, 1);
this.setData({
specs: newspecs
})
},
清空数据
this.setData({list:[]
});
数组转字符串
var a, b;
a = new Array(0,1,2,3,4);
b = a.join(“-“); //“0-1-2-3-4”
字符串转数组
var s = “abc,abcd,aaa”;
ss = s.split(“,”);// 在每个逗号(,)处进行分解 [“abc”, “abcd”, “aaa”]var s1 = “helloworld”;
ss1 = s1.split(‘’); //[“h”, “e”, “l”, “l”, “o”, “w”, “o”, “r”, “l”, “d”]