程序代码:
js:data: {
showdata:{},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that=this
that.setData({
good_id:options.good_id
})
console.log(options.good_id)
wx.showLoading({
title: '加载中',
})
wx.request({
url: getApp().globalData.server +'/index.php/Home/Goods/get_one_lol_goods', //仅为示例,并非真实的接口地址
data: {
good_id:options.good_id
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
method:'POST',
success (res) {
console.log(res.data)
if(res.data.error_code!=0){
wx.showModal({
title: '哎呀!',
content: '出错了呢'+res.data.msg,
showCancel:false,
success (res) {}
})
}
else if(res.data.error_code==0){
that.setData({
showdata:res.data.data
})
console.log(that.data.showdata)
}
},
fail:function (res) {
wx.showModal({
title: '哎呀!',
content: '网络不在状态呢',
success :function (res) {
if(res.confirm){
console.log('用户点击确定')
}else if(res.cancel){
console.log('用户点击取消')
}
}
})
},
complete:function (res) {
wx.hideLoading()
}
})
setTimeout(function(e){
wx.hideLoading()
},2000)
},
showdata:{},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that=this
that.setData({
good_id:options.good_id
})
console.log(options.good_id)
wx.showLoading({
title: '加载中',
})
wx.request({
url: getApp().globalData.server +'/index.php/Home/Goods/get_one_lol_goods', //仅为示例,并非真实的接口地址
data: {
good_id:options.good_id
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
method:'POST',
success (res) {
console.log(res.data)
if(res.data.error_code!=0){
wx.showModal({
title: '哎呀!',
content: '出错了呢'+res.data.msg,
showCancel:false,
success (res) {}
})
}
else if(res.data.error_code==0){
that.setData({
showdata:res.data.data
})
console.log(that.data.showdata)
}
},
fail:function (res) {
wx.showModal({
title: '哎呀!',
content: '网络不在状态呢',
success :function (res) {
if(res.confirm){
console.log('用户点击确定')
}else if(res.cancel){
console.log('用户点击取消')
}
}
})
},
complete:function (res) {
wx.hideLoading()
}
})
setTimeout(function(e){
wx.hideLoading()
},2000)
},
程序代码:
<block wx:for="{{showdata}}" wx:for-item="itemName" wx:for-index="id" wx:key="{{index}}">
<view class="box">
<view class="firstblock">
<image class="touxiang" src="{{itemName.image_url}}" mode="widthFix"></image>
<view class="person">
<view class="name">
<text class="showname">{{itemName.seller_name}}</text>
</view>
<view class="name">
<text class="showname2">{{itemName.good_name}}</text>
</view>
</view>
</view>
<view class="secondblock">
<text class="content"> {{itemName.content}}
</text>
</view>
<view class="thirdblock">
<view class='del' bindtap='buy' >购买</view>
</view>
</view>
</block>
<view class="box">
<view class="firstblock">
<image class="touxiang" src="{{itemName.image_url}}" mode="widthFix"></image>
<view class="person">
<view class="name">
<text class="showname">{{itemName.seller_name}}</text>
</view>
<view class="name">
<text class="showname2">{{itemName.good_name}}</text>
</view>
</view>
</view>
<view class="secondblock">
<text class="content"> {{itemName.content}}
</text>
</view>
<view class="thirdblock">
<view class='del' bindtap='buy' >购买</view>
</view>
</view>
</block>
本来渲染一条的情况,变成了渲染20条,而且实际内容为空白,求助各位编程高手解答