怎么在微信小程序中操作数组


在微信小程序中操作数组的方法: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 '

})

}

})


上一篇:linux如何查看磁盘空间大小

下一篇:微信小程序无法获取地理位置如何解决


微信小程序
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器