splice使用小程序问题

3991关注12255浏览

在使用splice时,我调用:

for (var index in that.data.studentData) {

if (that.data.studentData[index].id == sid) {

config = index;

break;

}

}

wx.showModal({

title: '提示',

content: '确定删除'+name+'的信息吗?',

success: function (res) {

if (res.confirm) {

var dta = that.data.studentData;

dta.splice(config, 1);

}

}

})可以正确删除第config位置的数据,

可是如果我使用:

for (var index in that.data.studentData) {

if (that.data.studentData[index].id == sid) {

config = index;

break;

}

}

var dta = that.data.studentData;

dta.splice(config, 1);

就有错,必须改为dta.splice(config-1, 1);才会正确删除第config位置的数据,这是为什么?

展开全部
收起
1回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • Evelyn

    5人对此回答表示赞同

    MDN上有对splice的详细讲解https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

    展开
    5
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部