小程序获取各种数据值跟设置数据值
来源:互联网 发布:初中毕业能学php吗 编辑:程序博客网 时间:2024/05/22 17:02
修改设置data数组中的某个值:
//小程序接收后台数据若为数组时,下标最好为默认索引数组,从0开始排序 var articleId ='1'//对应数组中的索引值 var thisArticle = "articleList[" + articleId + "].iscollection" console.log(thisArticle); that.setData({ //必须加[], [thisArticle]: ishow }) //若为索引值为定值:egarticleList[0].iscollection,则直接写,不用加[],必须加"" that.setData({ "egarticleList[0].iscollection": ishow })
小程序修改本页面data中数组中的某个值
//小程序data中的某个值若为数组时,下标最好为**关联**数组Page({ data: { teacherInfo:{ rachel1:{ name:"rachel", decoration: "加拿大人,两年多的线上英语教学经验友善耐心,为人随和。擅长烹饪喜欢影视音乐、跳舞更多", audioImg: "/ico_play.png", headImg:"/teacher.jpg", audioSrc:"/001.mp3", }, rachel2:{ name: "rachel", decoration: "加拿大人,两年多的线上英语教学经验友善耐心,为人随和。擅长烹饪喜欢影视音乐、跳舞更多", audioImg: "/ico_play.png", headImg: "/teacher.jpg", audioSrc: "/230.mp3", }, }, }, play:function(event){ var that = this; var id = event.currentTarget.dataset.id; console.log(id); var thisTeacher_autioImg = "teacherInfo."+id+".audioImg"; console.log(thisTeacher_autioImg); //解析: thisTeacher_autioImg 若写为这种[]格式("teacherInfo[" + id+ "].audioImg"),则直接修改整个数组,因为[]中只能是数字,若为"teacherInfo[3].audioImg",则teacherInfo数组变为4个值: teacherInfo:{0:null,1:null,2:null,3:{audioImg:"/ico_playing.png"}} //解析结束 that.setData({ [thisTeacher_autioImg]: "/ico_playing.png", playStatus: "pause", }) }, });
获取数组中某个变量的值:
var id = event.currentTarget.dataset.id; var a = that.data.teacherInfo[id].decoration;
获取自定义属性 data-id 的值:
event.currentTarget.dataset.id
小程序获取页面传值id 的值:
onLoad: function (options) { var that = this var articleId = options.id//获取文章的id值 },
小程序获取input框输入:
wxml:
<input type="number" placeholder="请输入手机号" bindinput="bindPhone" maxlength="11"/>
js:
bindPhone:function(e){ this.setData({ phone:e.detail.value }) },
阅读全文
0 0
- 小程序获取各种数据值跟设置数据值
- 下拉刷新获取数据的小程序
- struts2获取各种表单的数据小实例
- Angular获取数据各种方法
- 小程序数据请求
- 小程序数据缓存
- 各种控件显示初始数据、获取数据
- 小程序post提交获取数据,与服务器通信-小程序支付开发-视频教程5
- 深度学习常用的数据集,包括各种数据跟图像数据。
- 深度学习常用的数据集,包括各种数据跟图像数据。
- 小程序数据请求注意事项
- 小程序 后台数据请求
- struts2.0获取各种表单的数据
- struts2.0获取各种表单的数据
- 各种类型接口数据的获取方法
- 微信小程序 获取组件数据
- 各种程序内存与其上数据关系
- 获取控件的数据集 在设置主键 在获取该行某列的值
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(86)-日程管理-fullcalendar插件用法
- 安卓布局常见属性管理
- 「python」模块
- JavaScript基本类型和引用类型
- 任务管理器无法结束进程
- 小程序获取各种数据值跟设置数据值
- 初识Spring的注解
- 阿里云安全合作伙伴计划 新一轮招募开始
- HDU 1027
- mysql语法基础
- POI创建DOCX常用操作
- CMake: include called with wrong number of arguments. include() only takes one file.
- 目标检测3 Fast R-CNN
- android中的序列化和反序列化