当前位置: 首页 > news >正文

微信小程序调用map数据 并在wxml中对数组进行截取的操作

wxs文件的位置如图

 

实现数组截取 只保留五张图片

<wxs module="filter" src="./slicefunc.wxs"></wxs>
<view class="wrap"><view class="search-box" bindtap="toSearch"><view class="v1">搜索观察记录条目</view><view class="v2">搜索</view></view><view class="record-number">共有{{report.totalNumber}}条观察记录</view><view class="white-box" wx:for="{{report.recordDatas}}" wx:key="key" wx:for-index="key" wx:for-item="group"><view class="time">{{key}}</view><view class="item">      <view class="record-list" wx:for="{{group}}" wx:key="id"><view class="v1">{{item.recordDate}}</view><view class="record-student"><image mode="aspectFill" class="record-student-photo" wx:for="{{filter.sliceFunc(item.participants)}}" wx:for-item="mItem" wx:for-index="mIndex" wx:key="studentId" src="{{mItem.studentImage}}" /></view><view class="record-txt">{{item.content}}</view><view class="record-exercise">{{item.indicatorName}}</view></view>      </view></view></view>
// 支持es4语法
var filter = {sliceFunc: function(list){return list.slice(0,5)}
}
// 导出对外暴露的属性
module.exports = {sliceFunc: filter.sliceFunc
}

 ************这个是slicefunc.wxs里的内容是重点*****************************

以下的代码不重要 只是记录用的

const app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({data: {content: '',report: {}},onLoad(options) {},onShow() {const userInfo = wx.getStorageSync('userInfo');this.setData({userInfo})this.loadData()},loadData(){let oUserInfo = this.data.userInfoutil.request(api.listObservationRecord + oUserInfo.userId + '&&content=' + this.data.content, '', 'get').then(res => {if (res.code == 200) {let odata = res.data       this.setData({report: odata})} else {wx.showModal({title: res.msg,icon: 'error',showCancel: false,duration: 3000});}});},toSearch(){wx.navigateTo({      url: '../recordsearch/recordsearch'      })},
})
.wrap{ padding: 20rpx 0 0 10rpx;}
.search-box{ padding-right: 10rpx; margin-bottom: 10rpx; display: flex; align-items: center;}
.search-box .v1{ padding-left: 20rpx; flex: 1; height: 66rpx; line-height: 66rpx; background: #fff; font-size: 24rpx; color: #808080; border: 1rpx solid #eee; border-radius: 10rpx;}
.search-box .v2{ margin-left: 10rpx; width: 88rpx; height: 66rpx; text-align: center; line-height: 66rpx; background: #169bd5; font-size: 26rpx; color: #fff; border-radius: 10rpx;}
.record-number{ margin-top: 20rpx; font-size: 26rpx; font-weight: bold; color: #333;}.white-box{ margin-top: 22rpx; padding: 20rpx 20rpx 0 20rpx; width: 730rpx; box-sizing: border-box; background: #fff; border-radius: 25rpx;}
.time{ font-size: 26rpx; color: #015478;}
.item{ margin-top: 10rpx; display: flex; justify-content: space-between; flex-wrap: wrap;}
.record-list{ margin-bottom: 20rpx; padding: 20rpx; width: 335rpx; height: 225rpx; box-sizing: border-box; background: #f0f0f0;}
.record-list:last-child{ margin-right: 0;}
.record-list .v1{ margin-bottom: 10rpx; font-size: 24rpx; white-space: nowrap;}
.record-student{ display: flex; overflow-x: scroll;}
.record-student-photo{ margin-right: 10rpx; display: block; width: 50rpx; height: 50rpx; border-radius: 50%;}
.record-txt{ margin-top: 10rpx; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;font-size: 24rpx; color: #999;}
.record-exercise{ margin-top: 10rpx; font-size: 24rpx; color: #027db4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}

http://www.lryc.cn/news/122477.html

相关文章:

  • 前端项目打包
  • venv使用教程及pyvenv与python3-venv的区别
  • 协程(一)单机--》并发--》协程
  • P1722 矩阵 II
  • 【数据结构】树和二叉树的概念及结构
  • 8.1.tensorRT高级(3)封装系列-模型编译过程封装,简化模型编译代码
  • 化工行业案例 | 甄知科技助力万华化学重构IT服务价值,打造信息中心ERP!
  • day6 STM32时钟与定时器
  • 【JavaEE进阶】SpringBoot 配置文件
  • ResNet创新点总结
  • Scratch 之 3D 介绍及教程
  • 最强自动化测试框架Playwright(19)- 事件
  • 静态网页和动态网页区别
  • 美国服务器有哪些类型?
  • 【基因检测人工智能】如何使用JAVASCRIPT在HTML文档内部增加一个段落
  • unittest单元测试
  • 每天一道leetcode:72. 编辑距离(动态规划困难)
  • 详细介绍如何使用 OpenCV 对图像进行锐化
  • Java代理模式——静态代理与动态代理
  • Vue day02 Computed和Watch
  • 【Java】一只小菜坤的编程题之旅【3】
  • 全面掌握 Jaeger 分布式调用链路跟踪理论和实战,Go 为所有使用 go-resty 库发起 HTTP 请求集成链路跟踪 jaeger(附源码)
  • vue键盘和鼠标事件
  • Chrome 手动代理设置 HTTP/Socks5
  • SpringBoot第35讲:SpringBoot集成连接池 - 默认连接池HikariCP
  • 选择最适合自己的笔记本
  • 前端安全:探秘安全 HTTP 头的设置
  • python爬虫——爬虫伪装和反“反爬”
  • vue3 使用 element-china-area-data 实现地区选择器
  • STM32自带的DSP库的滤波初体验(一)