Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

for循环嵌套判断,会覆盖掉前面的内容怎么解决?

  for (let i in _this.person.data) {
          if (_this.person.data[i].classroom_id === _this.roomsId) {
            _this.onLine = _this.person.data[i].online_user_count
            _this.offLine = Number(_this.roomUsertData.length) - _this.person.data[i].online_user_count
            for (let j in _this.roomUsertData) {
              for (let o in _this.person.data[i].username) {
                if (this.roomUsertData[j].username === _this.person.data[i].username[o]) {
                  _this.$set(_this.roomUsertData[j], 'status', true)
                  _this.roomUsertData[j].status = true
                } else {
                  _this.$set(_this.roomUsertData[j], 'status', false)
                  _this.roomUsertData[j].status = false
                }
              }
            }
          }
        }

如果第一个为true了,但是下一个为false或覆盖掉true,想让他为true的话,就循环下一个this.roomUsertData[j] ........


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
for (let i in _this.person.data) {
  if (_this.person.data[i].classroom_id === _this.roomsId) {
    _this.onLine = _this.person.data[i].online_user_count
    _this.offLine = Number(_this.roomUsertData.length) - _this.person.data[i].online_user_count

    const usernameList = Object.keys(_this.person.data[i].username);
    for (let j in _this.roomUsertData) {
        const isInUserNameList = usernameList.includes(this.roomUsertData[j].username);        
        _this.$set(_this.roomUsertData[j], 'status', isInUserNameList);
        _this.roomUsertData[j].status = isInUserNameList;      
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...