You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

异步获取GitHub数据源时出现Uncaught (in promise) TypeError: episodeProp.album is undefined错误但页面仍可加载数据的问题求助

异步获取GitHub数据源时出现Uncaught (in promise) TypeError: episodeProp.album is undefined错误但页面仍可加载数据的问题求助

我正在尝试搭建一个简单的网站,从GitHub获取数据,我有两个数据集。

目前其中一个API能正常加载,但另一个会抛出错误:Uncaught (in promise) TypeError: album is not defined,奇怪的是网站居然还是能加载出数据!

我写了一个异步函数:

async function getData() {
    const previousPromise = fetch('https://raw.githubusercontent.com/balintov/matchmaker/refs/heads/main/previousPicturesAPI');
    const currentPromise = fetch('https://raw.githubusercontent.com/balintov/matchmaker/refs/heads/main/currentPicturesAPI');
    const responses = await Promise.all([previousPromise, currentPromise]);
    const dataPromises = responses.map(r => r.json());
    const [previous, current] = await Promise.all(dataPromises);
    for (var props in previous) {
        document.getElementById('main').innerHTML += `<div class="previousTitle"><h2> Korábbi részek </h2><p>${previous[props].series} évad</p></div>`
        for (var episodes in previous[props]) {
            for (var episode in previous[props][episodes]) {

                //THIS CONSOLE MESSAGE RETRIVES THE DATA
                console.log(previous[props][episodes][episode].album.photolink);

                var episodeProp = previous[props][episodes][episode];
                document.getElementById('main').innerHTML += `<div class="episode-container">
                    <div class="episode-head">
    
                /* HERE THE DATA WORKS, DOES NOT THROW MESSAGE */
                    <h2>${episodeProp.episode_date}</h2>
                    <p><a href=${episodeProp.episode} target="_blank">Hallgatom az epizódot!</a></p>
                    </div>
                    <div class="match-container">
                    <div class="album-container">
                    <div class="content-container">
                    <h3>Album</h3>
                /* FROM HERE THROWS THE ERROR MESSAGE */
                    <img src="${episodeProp.album.photolink}" alt="${episodeProp.album.description}" width="350" height="450" class="image">
                    <p>${episodeProp.album.song}</p><p><a href="${episodeProp.album.spotifylink}" target="_blank">Hallgatom 🎵</a></p>
                    </div>
                    </div>
                    <div class="picture-container">
                    <div class="content-container">
                    <h3>Kép</h3>
                    <img src="${episodeProp.picture.photolink}" alt="${episodeProp.picture.description}" width="350" height="450" class="image">
                    <p>${episodeProp.picture.description}</p>
                    </div>
                    </div>
                    </div>
                    </div>`
            }
        }
    }
}

getData();

我已经把数据集放到JSON校验工具里检查过,也把JS文件放到JS校验工具里验证过了。就像我在代码注释里说的,在模板字符串之前数据是有定义的,而且模板字符串里的部分数据也能正常工作。

具体的错误信息是:Uncaught (in promise) TypeError: episodeProp.album is undefined

我实在搞不懂问题出在哪,有没有人能给点提示呀?

备注:内容来源于stack exchange,提问作者balintov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:08:08