列表渲染,怎么分类?

小程序 文章 2022-03-09 17:20 0 全屏看文

列表渲染,怎么分类?List rendering, how to classify?

列表渲染,怎么分类?

//这是wxml<view class="container">  <view class="device-list">    <view class="device-month-list" wx:for="{{monthsList}}" wx:for-index="monthNuma">      <view class="device-month">        <text class="device-month-text">          <text class="device-month-value-text">{{item.workingMonthTime}}</text>          <text> 共计 </text>          <text class="device-month-value-text">{{item.totalArea}}</text>          <text></text>        </text>      </view>      <block wx:for="{{daysList}}" wx:for-item="item">        <view class="device-day-list" wx:for="{{item}}">          <view class="device-day">            <text class="device-day-text"> <text class="device-day-text-bold">{{item.workingTime}}</text> <text class="device-day-text" >共计 </text> <text class="device-day-text-bold">{{item.workingArea}}</text> <text class="device-day-text"></text>            </text>          </view>        </view>      </block>    </view>  </view></view>

返回的是所有月数据在一起

//这是数据解析setdayDevices(data) {    let tempList = [];    for (var i = 0; i < data.length; i++) {      tempList = Object.values(data[i].workRecords)      this.data.daysList.push(tempList)      this.setData({        daysList: this.data.daysList      })    }  }//这是截取的返回数据{	"statusCode": 200,	"data": [{		"workingMile": 28.086919990557952,		"workingArea": 337.046410350799,		"waterUsage": 1,		"oilUsage": 0,		"doseUsage": 0,		"workingTime": "2022-03",		"workRecords": {			"2022-03-08": {				"workingMile": 0.001977502063958132,				"workingArea": 0.023730262070118288,				"waterUsage": 0,				"oilUsage": 0,				"doseUsage": 0,				"workingTime": "2022-03-08"			}		}	}]}

怎么列表分类,三月的数据在三月里,二月的在二月的里面啊 跪求大佬指点

//这是wxml {{item.workingMonthTime}} 共计 {{item.totalArea}} {{item.workingTime}} 共计 {{item.workingArea}} 返回的是所有月数据在一起 //这是数据解析setdayDevices(data) { let tempList = []; for (var i = 0; i < data.length; i++) { tempList = Object.values(data[i].workRecords) this.data.daysList.push(tempList) this.setData({ daysList: this.data.daysList }) } }//这是截取的返回数据{ "statusCode": 200, "data": [{ "workingMile": 28.086919990557952, "workingArea": 337.046410350799, "waterUsage": 1, "oilUsage": 0, "doseUsage": 0, "workingTime": "2022-03", "workRecords": { "2022-03-08": { "workingMile": 0.001977502063958132, "workingArea": 0.023730262070118288, "waterUsage": 0, "oilUsage": 0, "doseUsage": 0, "workingTime": "2022-03-08" } } }]} 怎么列表分类,三月的数据在三月里,二月的在二月的里面啊 跪求大佬指点

回答:

八九:

简单的js逻辑。。你这算法不过关

fez:确实  要多敲
brave:

fez:啊? 需求要把月放在上面
brave:就是让你判断每个数据是否包含该关键词
比如 2022-03-08 包含 2022-03 那么这条数据就是3月份的
fez:他返回的数据 日期已经在三月里了
15:

建议先处理好数据再渲染,不过先wx:for和wx:if同时使用也不是不可以

微喵网络:

先在js里处理一遍数据

fez:我现在已经把数据处理成所有天数据都在一个一个数组里,是应该把每个月的数据都放在自己的数组里么?
微喵网络:对

-EOF-