溫馨提示×

怎么在微信小程序中操作數組

養魚的貓咪
1715
2021-04-21 11:58:17
欄目: 云計算

在微信小程序中操作數組的方法:1.使用push()函數向數組添加數據;2.使用split()函數刪除數組數據;3.使用setData方法修改數組數據;

怎么在微信小程序中操作數組

具體方法如下:

1.使用push()函數向數組添加一條數據

saveNote: function(e) {

var obj = e.detail. value;

var title = obj. title;

var detail = obj .detail;

if(tit1e.1ength<=0 || detail. 1ength<=0){

return;

}

this . data . notes. push(obj);

var update = this. data. notes;

console. log(update);

app. globalData.notes = update ;

wx. redirectTo({

url: ' . . /notes/notes '

})

}

2.使用split()函數刪除數組中的數據

Wx. showModal({

title: '提示',

content:'是 否刪除該紀錄',

success:function(res){

if(res. . confirm){

var notes =that. data. notes;

notes. splice(id,1);

that. setData({

notes: notes

})

console .1og("刪除成功");

}

}

})

3.使用setData方法修改數組中的數據

saveNote: function(e) {

var obj = e.detail. value;

var title = obj. title;

var detail = obj. detail;

if(tit1e.length<=0 || detail.length<=0){

return;

}

war that = this;

var notes =that . data. notes;

var id = that.data.id;

notes[id] = obj;

app. globalData.notes = notes;

WX . redirectToft({

url: ' . . /notes/notes '

})

}

})

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女