javascript - 类型错误:无法读取未定义的属性 'Eligible'

标签 javascript typeerror

我有这段 1 年前的代码,现在需要运行它。 欢迎任何可能的猜测。任何信息都会有所帮助,谢谢。

function getPrices(){
  let url = 'https://url/api/Prices/v4?key=' + key;
  var massive;
  let quality = '5';
  request({url:url, json:true},  function(err, res, body){
        if (err) console.log(err);

        massive = body.response.items;

        console.log('Prices received')
        for(let i = 0; i < data.length; i += 1){

          let get_json = other.urltojson(data[i].ApiLink);
          let particle = get_json.particle
          let name = data[i].BuyLink;
              name = name.replace(/(\/Eligible).*/, '');
              name = name.replace(/.*(\/)/, '');
              name = name.replace(/\%20/g, ' ');
              name = name.replace(/\%27/g, '\'')

          let comPrice = massive[name].prices[quality].Eligible.Suitable[definition].value;
          data[i].BuyPrice = comPrice;
        }
      });
}

错误日志:

          let comPrice = massive[name].prices[quality].Eligible.Suitable[definition].value;
                                                       ^

TypeError: Cannot read property 'Eligible' of undefined

最佳答案

这个错误意味着 massive[name].prices[quality] 给出了 undefined。

我不知道你的数据结构如何,但可能是你将 quality 存储为字符串而不是整数

编辑:

如果 massive[name].prices[quality]undefined,那么您进行回退可能是有意义的。

关于javascript - 类型错误:无法读取未定义的属性 'Eligible',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59509711/

相关文章:

python - 从 '_io.BytesIO' 转换为 python3.6 中的类字节对象?

python - Scrapy-类型错误: this constructor takes no arguments

字典的 Javascript 字典到基于第二层键的字典

php - 如何使用 $.ajax() 将字符串数组从 PHP 传递到 Javascript?

json - json 列表排序上的 flutter typeerror

node.js - Mongoose.js - TypeError : Model. deleteOne 不是函数

python-3.x - Sympy TypeError - 无法将浮点对象解释为整数

javascript - JSON 导入/导出格式的文件扩展名

javascript - React 单选输入仅在单击标签时发生变化

javascript - jqgrid 复选框更改事件