You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git/scr/food/pages/detail/detail.js

106 lines
2.0 KiB

2 years ago
// pages/detail/detail.js
const db = wx.cloud.database({});
const cont = db.collection('food');
Page({
/**
* 页面的初始数据
*/
data: {
detailObj: {},
index: null,
list:[],
clockresult:[],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.clockData()
let id =options.id
cont.doc(id).get()
.then(res => {
console.log('22')
console.log('食物详情页', res)
this.setData({
detailObj: res.data
})
})
},
// 渲染数据
clockData() {
var _this = this
wx.request({
url:'/pages/index/index'+ this.data.index, //url this.data.index是id
method: 'GET', //请求方式
header: {
'content-type': 'application/json'
}, // 设置请求的 header
success: function (res) {
let list = [];
let box = (res.data.obj.assignDates === null) ? [] : res.data.obj.assignDates.substring(0, res.data.obj.assignDates.length - 1).replace(/,/g, " ")
//这里的效果跟上面的是一样的效果就是不用foeEach循环了就是另一种方法这个较麻烦一点
list.push((box.length <= 0) ? [] : box.split(' '))
_this.setData({
list,
clockresult: res.data.obj,
})
},
fail: function () {
app.consoleLog("请求数据失败");
},
complete: function () {
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})