小程序修改数组中对象的某个值或者修改对象值
生活随笔
收集整理的這篇文章主要介紹了
小程序修改数组中对象的某个值或者修改对象值
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
小程序中獲取當(dāng)前data定義的值,用this.data.xxx
setData的時(shí)候要修改的值是不需要加this.data.xxx的,直接xxx,
一般直接修改data的值直接修改,修改數(shù)組中對(duì)象的值或者對(duì)象的屬性值都要先轉(zhuǎn)為字符串再加中括號(hào),如果有變量可以用ES6的模版字符串反單引號(hào)或者字符串拼接一下。
Page({data: {currentValue:"aa",todoLists:[{detail:"",date:"",location:"",priority:"",remark:"",dateStatus:false,locationStatus:false,dateRepeat:false,completeStatus: false,currentInput:'',},{detail: "",date: "",location: "",priority: "",remark: "",dateStatus: false,locationStatus: false,dateRepeat: false,completeStatus: false,currentInput:'',}],aa:{a:1,b:2}},tickToComplete:function(e){//修改數(shù)組中對(duì)象的值let index = e.currentTarget.dataset.index;let completeStatus = `todoLists[${index}].completeStatus`;this.setData({[completeStatus]: !this.data.todoLists[index].completeStatus})//修改對(duì)象中的屬性值this.setData({['aa.a']: 3})console.log(this.data.aa.a); //3//修改普通data值this.setData({currentValue: "bbb"})},?
更多專(zhuān)業(yè)前端知識(shí),請(qǐng)上 【猿2048】www.mk2048.com
總結(jié)
以上是生活随笔為你收集整理的小程序修改数组中对象的某个值或者修改对象值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 小程序在父组件执行子组件方法,可适用于下
- 下一篇: koa中上传文件到阿里云oss实现点击在