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

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. Spring第一个程序

    目录 1.利用Maven导入jar包 2.编写一个实体类 3.编写Spring文件 4.测试 1.利用Maven导入jar包 <dependency> <groupId>org ...

  2. 引用element-ui的Drawer抽屉组件报错问题

    前提:vue项目采取按需引入的方式引入element,并且使用其他组件都正常,没有发生异常 问题表现: 在vue项目中引用了Drawer 抽屉组件,结果报错 意思就是组件未注册,当时我的表情: 没办法 ...

  3. 『无为则无心』Python函数 — 30、Python变量的作用域

    目录 1.作用于的概念 2.局部变量 3.全局变量 4.变量的查找 5.作用域中可变数据类型变量 6.多函数程序执行流程 1.作用于的概念 变量作用域指的是变量生效的范围,在Python中一共有两种作 ...

  4. [学习笔记] Oracle创建用户、分配权限、设置角色

    创建用户 create user student --用户名 identified by "123456" --密码 default tablespace USERS --表空间名 ...

  5. 『无为则无心』Python函数 — 32、递归

    目录 1.什么叫递归函数 2.递归的应用场景 3.递归的特点 4.应用:3以内数字累加和 5.应用:阶乘 6.总结 1.什么叫递归函数 Python中,在函数内部,可以调用其他函数.如果一个函数在内部 ...

  6. 初识python: 反射

    反射:通过字符串映射或修改程序运行时的状态.属性.方法 反射有以下三个方法: hasattr(object, name)           判断一个对象(object)里是否有对应的字符串(name ...

  7. 用软碟通UltraISO刻录Win 10 1909 到U盘,只有1个G左右,安装不了系统

    之前一直用软碟通刻录WIN10的ISO镜像到U盘.最近想到用最新版的WIN10 1909 来做一个U盘系统,刻录也成功了.就是安装系统的时候总报错,找了很久原因,终于发现刻录后占用U盘的空间只有1G左 ...

  8. 安装Cacti-plugin

    安装pluginunzip cacti-plugin-0.8.7e-PA-v2.6.zip -d cacti-plugin-archcp -R cacti-plugin-arch/* /data/ww ...

  9. SYCOJ906瑞士轮

    题目-瑞士轮 (shiyancang.cn) 模拟题 #include<bits/stdc++.h> using namespace std; const int N=1e5+520; i ...

  10. 华为HMS Core全新推出会员转化&留存预测模型

    现在,付费学知识,付费听歌,付费看电视剧,付费享受线上购物优惠--等等场景已经成为大部分年轻人的日常. 而对于企业商家来说,付费会员作为企业差异化用户运营的手段,不仅有利于提升用户的品牌忠诚度,在当下 ...