繁体   English   中英

JavaScript如果未返回true

[英]Javascript if does not return true

我有一个奇怪的JavaScript问题。 我正在使用vue js和axios从API获取一些数据。 我已经转储了console.log并且值在那里,但是我的if语句将不正确。

已删除内容,因此代码示例较小。

查看内联注释。

HTML:

<input v-model="system_id">
<button v-on:click="getSystemData" class="btn btn-primary">Get system data</button>


Data model:

data: () => ({
  errors: [],
  system_id: null,
  system_data: null
}),



Function:

getSystemData () {
    HTTP.get('/api/get_systems')
    .then(response => {
      this.response = response.data

      // equals 1234
      console.log(this.system_id)
      for (var key in this.response) {

        // the id 1234 is found here in a large list
        console.log(this.response[key].system_id)


        // Does not go true?!?!
        if (this.response[key].system_id === this.system_id) {
          this.system_data = this.response[key].system_data
        }
      }
    })
    .catch(e => {
      this.errors.push(e)
    })
  }

为什么如果永不触发?

问题可能出在数据类型不匹配上。 ===运算符将为if(1234 ===“ 1234”)返回false。 使用==运算符

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM