小程序前后台交互(集合和对象)
wxml:
<!-- 对象展示数据 -->
<!-- <view>
<view>影院编码:{{result.placeno}}</view>
<view>名称:{{result.spname}},</view>
<view>介绍:{{result.introduce}},</view>
<view>url:{{result.spimgurl}}</view>
<view>spno:{{result.spno}},</view>
</view> -->
<!-- 集合展示数据 -->
<view wx:for = "{{result}}" data-index="{{index}}" wx:for-item="item" wx:key="{{index}}" bindtap="selectIdx">
<view>{{item[index].memberno}}</view>
<view>{{item.spname}}</view>
</view>
js:
data: {
result:[],//初始化
index: 0
},
onLoad: function (options) {
this.setData({
type: options.type,
})
console.log(options.type);
var _this = this;
wx.request({
method: "GET", //注意请求方式必须要大写!!!
url: 'http://localhost:8081/WxMiniapp/MemCpn/splist',//测试接口
header: { 'content-type': 'application/json' }, //content-type必须要小写!!!
success: function (res) {
console.log(res)
var splist = res.data.splist;
console.log(splist, '数据列表')
_this.setData({
result: res.data.splist
})
}
})
},
项目目录:
展示数据:
控制台打印: