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

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. 关于python常用的命令

    os模块: os.system os.system("cat/cmd等...") os.popen print os.popen("adb shell ls ../aa. ...

  2. C++ 虚函数和友元

    虚函数具有动态联编性,在类族中有强大功能:友元函数具有跨类访问的功能,本质却是一种对封装的破坏. 先看这样一个例子: #include<iostream> using namespace ...

  3. 【Redis的那些事 · 续集】Redis的位图、HyperLogLog数据结构演示以及布隆过滤器

    一.Redis位图 1.位图的最小单位是bit,每个bit的值只能是0和1,位图的应用场景一般用于一些签到记录,例如打卡等. 场景举例: 例如某APP要存储用户的打卡记录,如果按照正常的思路来做,可能 ...

  4. 云南农职《JavaScript交互式网页设计》 综合机试试卷①——实现购物车的结算

    一.语言和环境 实现语言:javascript.html.css. 开发环境:HBuilder. 二.题目2(100分) 1.功能需求: 马上过节了,电商网站要进行促销活动,需要实现该商城购物车的商品 ...

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

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

  6. 如何修改文件的 “创建时间” 和 “修改时间”(Windows Linux macOS)

    请访问原文链接:https://sysin.org/blog/how-to-change-file-date,查看最新版.原创作品,转载请保留出处. 作者:gc(at)sysin.org,主页:www ...

  7. python + pymysql连接数据库报“(2003, "Can't connect to MySQL server on 'XXX数据库地址' (timed out)")”

    python + pymysql连接数据库报"(2003, "Can't connect to MySQL server on 'XXX数据库地址' (timed out)&quo ...

  8. for update未提交导致锁表

    select for update 是为了在查询时,避免其他用户以该表进行插入,修改或删除等操作,造成表的不一致性. 应用场景: 什么时候需要使用for update?就是那些需要业务层面数据独占时, ...

  9. docker查看容器的ip地址

    查看Docker的底层信息. docker inspect 会返回一个 JSON 文件记录着 Docker 容器的配置和状态信息 # 列出所有容器的IP地址docker inspect --forma ...

  10. CentOS7中安装pip的方法

    1.安装epel-release [root@localhost ~]# yum -y install epel-release 2.安装python-pip [root@localhost ~]# ...