//wxml
{{item.name}}
删除
创建仓库
//JS
Page({
/**
* 页面的初始数据
*/
data: {
title:null,
store_name:null,
storeList:[],
num:null,
total:null,
beachTimes:null,
},
//获取仓库信息
getStoreList(){
const max_num = 20;
db.collection('store').count().then(res=>{
console.log(res)
this.setData({
total:res.total,
})
this.setData({
beachTimes:Math.ceil(this.data.total/20)
})
console.log(this.data.beachTimes)
console.log(this.data.total)
var list = [];
for(let j = 0;j{
console.log(rez)
for(let i = 0;i
问题已解决感谢各位大佬:
wxml:
<!--显示现有仓库-->
<scroll-view scroll-y="true" class="showStore" style="height: 1000rpx;">
<block wx:for="{{storeList}}" wx:key="index">
<view class="name">{{item.store_name}}</view>
<view class="delete" data-id="{{item._id}}" bindtap="delStore">删除</view>
</block>
</scroll-view>
<!--提交表单-->
<form action="submit" bindsubmit="createStore">
<input type="text" name="storename" placeholder="请输入仓库名称"/>
<button class="createSt" bindtap="flashPage" type="primary" form-type="submit" >创建仓库</button>
</form>
JS:
//获取仓库信息
getStoreList(){
const max_num = 20;
db.collection('store').count().then(res=>{
console.log(res)
this.setData({
total:res.total,
})
this.setData({
beachTimes:Math.ceil(this.data.total/20)
})
console.log(this.data.beachTimes)
console.log(this.data.total)
var list = []
var olddata = []
for(let j = 0;j<this.data.beachTimes;j++){
db.collection('store').skip(j*max_num).limit(max_num).get().then(ress=>{
olddata=ress.data
list = olddata.concat(list)
console.log(list)
this.setData({
storeList:list
})
})
}
})
console.log('storeList是',this.data.storeList)
},
控制台:
主要是循环判断的this.data.total可能出现与rez.data长度不匹配的情况,加判断this.data.total不得大于res.data的长度
看下数据格式,对应渲染
数据取到了,前端页面没显示了,求大佬解答!