1. 程式人生 > >小程式指定更改陣列或物件中的某一個值

小程式指定更改陣列或物件中的某一個值

1、更改陣列中的值

設 paraList:[{txt:'123',chose:false},{txt:'1234',chose:false}]

let choseChange = "paraList[" + index + "].chose" _this.setData({ [choseChange]: true, numList: numList })可以改變陣列中某一個特定下標的值

2、更改物件中的值

userInfo: { // 使用者的驗證資訊 sex: '', name: '', phone: '', code: ''
, sexTxt:'請選擇你的性別', nameTxt:'名字不能為空', phoneTxt: '手機號不能為空', codeTxt: '獲取驗證碼', codeErrTxt:'驗證碼不能為空' },let userSex = "userInfo.sex"_this.setData({ [userSex]: '1'})

可以單獨更改userInfo中的sex值