我有这段 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/