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]
给出未定义的。
我不知道您的数据结构如何,但可能是您将您的数据存储quality
为字符串而不是整数
编辑:
massive[name].prices[quality]
如果is进行后备可能对您来说是有意义的undefined
。
推荐阅读
- firebase - 尝试从 Firebase 管理员发送消息时发生超时
- c# - 如何从 HttpCall 读取我的自定义 Flurl 标头
- emacs - 如何在emacs org-mode中为引用块命名
- excel - MS Excel 公式:删除重复项、空格、根据条件按字母顺序排序
- mysql - Drupal 7 函数 db_insert() 导致内部服务器错误 (500)
- android-studio-3.5 - Gradle 同步锁
- excel - 英语和德语的通用日期格式公式
- reactjs - react native + redux(更新其他组件在同一屏幕上听到的状态)
- c++ - 调试时无法输入vscode
- javascript - 如何检查浏览器是否支持 HTML5 postMessage?Javascript