l***@foxmail.com
l***@foxmail.com
  • 发布:2018-09-20 16:07
  • 更新:2018-09-20 16:23
  • 阅读:2076

原生js remove方法冲突

分类:uni-app

data:{
uploadimgs: []
}
that.uploadimgs.concat(res.tempFilePaths) 使用正常
that.uploadimgs.remove(e.currentTarget.dataset.index)//使用异常
page handleProxy function TypeError: this.uploadimgs.remove is not a function

重写后concat使用异常
Array.prototype.remove = function(i){
const l = this.length;
if(l==1){
return []
}else if(i>1){
return [].concat(this.splice(0,i),this.splice(i+1,l-1))
}
}

2018-09-20 16:07 负责人:无 分享
已邀请:
l***@foxmail.com

l***@foxmail.com (作者)

已解决,重写扩展remove方法
Array.prototype.remove=function(obj){
for(var i =0;i <this.length;i++){
var temp = this[i];
if(!isNaN(obj)){
temp=i;
}
if(temp == obj){
for(var j = i;j <this.length;j++){
this[j]=this[j+1];
}
this.length = this.length-1;
}
}
}

Trust

Trust - 少说废话

该问题目前已经被锁定, 无法添加新回复