请问不想写这么多if else 怎么办?
if (params.username == '' && params.company == '' && params.project == '' && params.bigclassname == '') {
wx.cloud.database().collection("demoorder").where({
date: _.gte(new Date(params.startDate)).and(_.lte(new Date(params.endDate)))
})
.skip(len)
.limit(20)
.get({
success(res) {
},
fail(res) {
}
})
} else if (params.username != "" && params.company == "" && params.project == "" && params.bigclassname == "") {
wx.cloud.database().collection("demoorder").where({
date: _.gte(new Date(params.startDate)).and(_.lte(new Date(params.endDate)))
})
.skip(len)
.limit(20)
.get({
success(res) {
},
fail(res) {
}
})
} else if (params.username == "" && params.company != "" && params.project == "" && params.bigclassname == "") {
wx.cloud.database().collection("demoorder").where({
date: _.gte(new Date(params.startDate)).and(_.lte(new Date(params.endDate)))
})
.skip(len)
.limit(20)
.get({
success(res) {
},
fail(res) {
}
})
}else if{}等等
onLoad里:
this.query = {}
动态改变this.query = {...}
db.collection(xxx).where(this.query).update()
db.collection(xxx).where(this.query).update() 如果this.query={_id,_.in([1,2,3])}就会出错 简单的查询没有问题,比如this.query={_id:1}
let endParams = {};
if (params.username != ''){
endParams.username = params.username;
}
if (params.password != ''){
endParams.password = params.password;
}
wx.cloud.database().collection("demoorder").where(endParams)...
// 抱歉回复的比较晚了~~~
let endParams = {};
if (params.username != ''){
endParams.username = params.username;
}
if (params.password != ''){
endParams.password = params.password;
}
wx.cloud.database().collection("demoorder").where(endParams)...