在数组中添加了一个新的元素为渲染是出错?
发布于 7 年前 作者 na50 6699 次浏览 来自 官方Issues

这在数组中新加入了一个元素,然后不可以渲染

console.log(wx.getStorageSync('children'))
      var children = wx.getStorageSync('children');
      var newChildList = [];
      // 解绑
      if(children.length>=reports.length){
        //对获取到的新学生列表和当前列表进行比对去重
          for (var i in children) {
            for (var j in reports) {
              if (children[i].id == reports[j].id) {
                children[i].avatarUrl = reports[j].avatar_url;
                children[i].name = reports[j].display_name;
                children[i].groupName = reports[j].group.name;
                children[i].centerName = reports[j].center.name;
                newChildList.push(children[i]);
              }
            }
        }
        console.log(newChildList)
      } else {
        //添加
        //将array转换为可以让其绑定的格式的map
        var child_map=reports.map(item=>({
          id: item.id,
          name: item.display_name,
          firstName:null,
          lastName:null,
          avatarUrl:item.avatar_url,
          birthday:null,
          groupName : item.group.name,
          centerName : item.center.name,
          loginResponse:null,
          age:null,
          agencyName:null,
        }))
        // 新的小孩添加到新的列表中
        newChildList.push(child_map)
        console.log(child_map)
      };
//判断当前学生是否还存在
      var isExist = false,
        index;
      // 记录当前child在新的列表中的位置
      for (var i in newChildList) {
        if (newChildList[i].id == app.globalData.currentChild.id) {
          index = i;
          isExist = true;
        }
      };
      //如果当前学生被删除,就取学生列表第一位的学生为当前学生
      if (!isExist) {
        app.globalData.currentChild = newChildList[0];
        wx.setStorageSync('currentChild', newChildList[0]);
        that.setData({
          currentChild: newChildList[0]
        })
      } else {
        app.globalData.currentChild = newChildList[index];
        console.log(newChildList[index])
        wx.setStorageSync('currentChild', newChildList[index]);
        console.log(wx.getStorageSync('currentChild'))
        that.setData({
          currentChild: newChildList[index]
        })
      }
      wx.setStorageSync('children', newChildList);
      app.globalData.children = newChildList;
3 回复

500是服务器错误,找后台看下

提示的是图片加载出错

只是你wxml里没给图片加 wx:if吧。。不影响渲染啊

回到顶部