1 $(document).on('click','.fileclose',function(){ 2 var fileList = taskNode['file']; 3 var newFileList = []; 4 var wrapId=($(this).parents('.layui-col-md3').attr('id')); 5 for (var i = 0; i < fileList.length; ++i) { 6 if(fileList[i].id != wrapId){ 7 newFileList.push(fileList[i]); 8 } 9 } 10 taskNode['file'] = newFileList; 11 var fileId = ''; 12 console.log(newFileList) 13 for(var i=0; i<newFileList.length; ++i) { 14 fileId += newFileList[i].id + ","; 15 } 16 taskNode['fileid'] = fileId; 17 $(this).parents('.layui-col-md3').remove(); 18 console.log(nodes) 19 })
基本逻辑:
1.创建一个新数组;
2.循环遍历旧数组;
3.当旧数组中的值不等于某个固定的值的时候,将其加入到新数组中;
4.将新数组赋值给旧数组所属对象