大神求解 这个怎么会多一条数据 length被当成一条数据输出了

发布于 6 年前作者 guiyingyao10386 次浏览最后编辑 6 年前来自 ask
  • 当前 Bug 的表现(可附上截图)

  • 预期表现

  • 复现路径

  • 提供一个最简复现 Demo

 

这个是代码

3 回复
xiuying14
xiuying141 楼6 年前

currData初始化为对象,执行_Array.prototype.push.apply(currData, jsonObj.object)_使其成为了伪数组(key值为0,1,2…索引并有length属性的对象),可以通过_Array.prototype.slice.call(currData)_转成数组。

gongxia
gongxia2 楼6 年前

 

  loadSignReplyInfo: function() {

var _this=this  

    wx.request({

      url:“”

      success: function(res) {

        console.log(“reply”);

        console.log(res);

        //var jsonObj = JSON.parse(res.data);

        var jsonObj = res.data;

        if (jsonObj.statusCode == 200) {

 

          var currData = {};

          if (_this.data.pageNum == 1) {

            currData = jsonObj.object;

          } else if (_this.data.pageNum != 1) {

            currData = _this.data.signReplyList

            // currData = currData.concat(jsonObj.object);

            Array.prototype.push.apply(currData, jsonObj.object)

          }

          console.log(“currData”)

          console.log(currData)

          _this.setData({

            signReplyList: currData,

            replypageNum: pageNum + 1,

            replysearchLoading: false

          })

        }

        if (jsonObj.statusCode == 205) {

          _this.setData({

            replysearchLoading: false

          })

        }

      }

    })

  },

min46
min463 楼4 年前

把数组变成对象?你用的啥方法啊