收藏
回答

在数组中添加了一个新的元素为渲染是出错?

这在数组中新加入了一个元素,然后不可以渲染
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;


最后一次编辑于  11-25
回答关注问题邀请回答
收藏

3 个回答

  • var 友原
    var 友原
    11-25

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

    11-25
    赞同
    回复
  • 卢霄霄
    卢霄霄
    11-25

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

    11-25
    赞同
    回复
  • 小鸡叫叫
    小鸡叫叫
    11-25

    提示的是图片加载出错

    11-25
    赞同
    回复 1
    • Kay三石
      Kay三石
      11-25
      明白哪里出错了
      11-25
      回复
问题标签