微信小程序获取各种数据值跟设置数据值。
//小程序接收后台数据若为数组时,下标最好为默认索引数组,从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人参与
发表评论: