问题描述:
ajax返回一个对象数组,页面内通过v-for输出,但是每个循环元素内要添加一个input输入框
提交时候,需要连同input值一起提交

初期思路
步骤:
1.直接对ajax返回的json对象数组通过for循环追加属性,
2.data变量在渲染以后结构发生变化,如何取值

解决方法:
1.ajax返回的结果先赋值给临时变量temp
2.通过for循环给temp数组内的对象添加新属性result
3.把temp赋值给projectList
表单提交时候:
通过 document.querySelectorAll(“.rusult_input”);获取到追加input的值,通过for再循环赋值

尝试改进:
1.用map函数处理数据

data.map(function(item){
  item.show = false;
});

2.数据在created钩子中请求及追加

用map函数追加属性

getinfoList(){
      this.$ajax.get('/service/check/15/LABS_CHECK?pageSize=1000')
      .then((res)=>{
        this.infoList=res.data.body.list;
        this.infoList.map(function(item){     
          if(item.checkResult.length>0){
            item.uploadTypeText=true;     //条件判断追加属性
            item.uploadTypeImg=false;     //条件判断追加属性
          };
          if(item.images.length>0){
            item.uploadTypeText=false;
            item.uploadTypeImg=true;
          };
        });
        console.log(this.infoList);
      })
      .catch(function (error) {});
    }
作者 铁血 汉子 2017年11月8日
2024/04/30/06:24:20am 2017/11/8/4:40:45
0 1994