思路:用数据驱动事件,用数组的方式去对循环数组的每个对象进行操作

js代码:

data:{

selectCategory: [{ name: '生产模式', content: [{ txt: '原厂' }, { txt: '生产代工' }, { txt: '生产设计' }, { txt: '其他' }] }, { name: '货源类别', content: [{ txt: '现货' }, { txt: '需采购' }, { txt: '需生产' }, { txt: '其他' }] }, { name: '出货周期', content: [{ txt: '现货' }, { txt: '需采购' }, { txt: '需生产' }, { txt: '其他' }] }, { name: '发货地省份', content: [{ txt: '北京' }, { txt: '上海' }, { txt: '湖南' }, { txt: '广东' }, { txt: '浙江' }]}],
rotateAnimation:[], //箭头旋转动画
animationOff:[false,false,false,false] //控制筛选内容的显示开关

}

给每个人数组添加新属性:(checked:false)

onLoad:function (options) {
this.setAnimation();
let { selectCategory, save } = this.data;
selectCategory.forEach(x=>{
x.content.filter(x=>{
x.checked = false
})
})
this.setData({
selectCategory
})
},
动画方法:
//箭头动画
makeAnimate(e){
let {index}=e.currentTarget.dataset;
let { rotateAnimation, animationOff}=this.data;
let animation=wx.createAnimation({
duration:200,
timingFunction:'linear',
delay:0
})
if (animationOff[index]){
animation.rotate(0).step();
}else{
animation.rotate(180).step();
}
rotateAnimation[index] = animation.export();
animationOff[index] = !animationOff[index];
this.setData({
rotateAnimation: rotateAnimation,
animationOff: animationOff
})
}
//wxml代码
<view class="category-block" wx:for="{{selectCategory}}" wx:key="">
<view class="category-title" data-index="{{index}}" bindtap="makeAnimate">
<text class="category">{{item.name}}</text>
<image animation="{{rotateAnimation[index]}}" src="/images/down.png"></image>
</view>
<view class="category-cnt" wx:if="{{animationOff[index]}}">
<text class="txt-style {{childItem.checked?'bg-color':''}}{{index==3?'save':''}}" data-index="{{index}}" data-childIndex="{{chidIndex}}" bindtap="checked" wx:for-index="chidIndex" wx:for="{{item.content}}" wx:for-item="childItem" wx:key="">{{childItem.txt}}</text>
</view>
</view>

微信小程序--给数组的每个对象添加动画(数据驱动)的更多相关文章

  1. 【微信小程序】数组操作

    Page({ data: { list:[{ id:1, name:'应季鲜果', count:1 },{ id:2, name:'精致糕点', count:6 },{ id:3, name:'全球美 ...

  2. 微信小程序基于腾讯云对象存储的图片上传

    在使用腾讯云对象存储之前,公司一直使用的是传统的FTP的上传模式,而随着用户量的不断增加,FTP所暴露出来的问题也越来越多,1.传输效率低,上传速度慢.2.时常有上传其他文件来攻击服务器,安全上得不到 ...

  3. 微信小程序之数组操作:push与concat的区别

    微信小程序中需要用到数组的操作,push和concat二者功能很相像,但有两点区别. 先看如下例子: var arr = []; arr.push(); arr.push(); arr.push([, ...

  4. 微信小程序传数组(Json字符串)到Java后端

    一:小程序端: wxml中代码: <!--index.wxml--> <view> <view> <button bindtap="onShow&q ...

  5. 微信小程序data数组push和remove问题

    因为在做一个小程序的demo时.由于不向后台请求数据,所以就涉及到对本地数据的操作,现在就做一些数组的增删 //添加新元素 addItemFn: function () { var { lists } ...

  6. 微信小程序 获取数组长度

    wxml中直接 {{array.length}} js中 array.length 小程序调用API返回的数据全部都是异步的:所以前提是要确保array中的数据,是存在的

  7. 微信小程序之自定义底部弹出框动画

    最近做小程序时,会经常用到各种弹框.直接做显示和隐藏虽然也能达到效果,但是体验性太差,也比较简单粗暴.想要美美地玩,添加点动画还是非常有必要的.下面做一个底部上滑的弹框. wxml <view ...

  8. 微信小程序:给data中对象中的属性设置值与给data中的属性或对象或数组设置值的区别

    一.给data中的属性或对象或数组设置值,属性名不需要加引号 this.setData({ material: param, // 这里material为对象 } this.setData({   d ...

  9. 微信小程序删除数组(删除对应指定下标数组中的元素)

    .js 使用arr.splice(id,1)删除 // 删除数组中指定下标 dele_time: function (e) { console.log('删除') console.log(e.curr ...

随机推荐

  1. Codeforces 1076G Array Game 题解

    目录 题目大意 做法 代码 不想写昨天晚上cf的比赛题目所以来写题解摸摸鱼 题目大意 有一个在长度为\(k\)的正整数序列\(b\)上进行的游戏,一开始一个棋子放在位置\(1\),假如当前棋子的位置为 ...

  2. NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis

    目录 概 主要内容 positional encoding 额外的细节 代码 Mildenhall B., Srinivasan P. P., Tancik M., Barron J. T., Ram ...

  3. Not All Samples Are Created Equal: Deep Learning with Importance Sampling

    目录 概 主要内容 "代码" Katharopoulos A, Fleuret F. Not All Samples Are Created Equal: Deep Learnin ...

  4. 基于Spring MVC + Spring + MyBatis的【物流系统 - 公司信息管理】

    资源下载:https://download.csdn.net/download/weixin_44893902/45601768 练习点设计:模糊查询.删除.新增 一.语言和环境 实现语言:JAVA语 ...

  5. HTML网页设计基础笔记 • 【第3章 表单】

    全部章节   >>>> 本章目录 3.1 表单 3.1.1 表单概述 3.1.1 表单概述(续) 3.1.2 表单标签 3.1.3 表单数据的提交方式 3.2 输入框和按钮 3 ...

  6. playwright--自动化(二):过滑块验证码 验证码缺口识别

    前两天需要自动化登录一个商城的后台 用的是playwright 没有用selenium 中间出了一个滑块验证 现阶段playwright教程不是太多,自己做移动的时候各种找,费劲巴拉的.现在自己整出来 ...

  7. Fences桌面图标分类

    1.简介 Fences也称为栅栏桌面, 可以用来分类和组织桌面上的图标. Fences可以将不同的图标放到不同的容器当中, 还可以自由的设置这个容器,比如移动和拉伸等等. 这样图标分类后,桌面就整洁多 ...

  8. C语言 Make命令教程

    make只是一个根据指定的Shell命令进行构建的工具 在linux和unix中,有一个强大的使用程序,叫make,可以用它来管理多模块程序的编译和链接,直至生成可执行文件 make使用程序读取一个说 ...

  9. JS 利用新浪接口通过IP地址获取当前所在城市

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">< ...

  10. nginx配置指定域名访问,nginx禁止ip访问,配置空主机头 syscal

    1.大家有过这方面的困扰,就是自己的网站给其他人恶意域名解析到自己的服务器ip上. 特别不爽,那大家可以用用空主机头的方法. 先给大家看下我的nginx.conf配置 http { log_forma ...