简体   繁体   English

未捕获的类型错误:无法读取未定义的属性“对象”

[英]Uncaught TypeError: Cannot read property 'object' of undefined

So this is my first ever question and I'm new here.所以这是我的第一个问题,我是新来的。 So I'm attending course on Udemy for javascript and this is my problem:所以我正在参加 Udemy 的 javascript 课程,这是我的问题:

I define a parameter(object) before executing a function but the browser throws an error on it.我在执行函数之前定义了一个参数(对象),但浏览器在它上面抛出了一个错误。 So I console.log it before executing function and it returns the data like it suppose to be, but when using in a function it errors out that it's undefined.所以我在执行函数之前对它进行 console.log 并返回它假设的数据,但是在函数中使用时它会错误地指出它是未定义的。

After losing hope at trying to find mistake I even copy paste code from the original program from the course but it still throws mistake!在对试图找出错误失去希望之后,我什至从课程中复制了原始程序中的粘贴代码,但它仍然会抛出错误! So I think it's not a problem with the code but something else.所以我认为这不是代码的问题,而是其他问题。 Maybe you know what?也许你知道什么? Here is the code anyway.无论如何,这是代码。

const controlList = () => {
    // Create a new list IF there in none yet
    if (!state.list) state.list = new List();

    // Add each ingredient to the list and UI
    console.log(state.recipe.ingredients);
    state.recipe.ingredients.forEach(el => {
        const item = state.list.addItem(el.count, el.unit, el.ingredient);
        console.log(state.list.items);
        console.log(item);            // HERE IS OK
        listView.renderItem(item);   // THIS LINE THROWS MISTAKE
    });
}

export const renderItem = item => {
    const markup = `
        <li class="shopping__item" data-itemid=${item.id}>
            <div class="shopping__count">
                <input type="number" value="${item.count}" step="${item.count}" class="shopping__count-value">
                <p>${item.unit}</p>
            </div>
            <p class="shopping__description">${item.ingredient}</p>
            <button class="shopping__delete btn-tiny">
                <svg>
                    <use href="img/icons.svg#icon-circle-with-cross"></use>
                </svg>
            </button>
        </li>
    `;
    elements.shopping.insertAdjacentHTML('beforeend', markup);
};

// controlList() is called in the event listener here // controlList() 在这里的事件监听器中被调用

elements.recipe.addEventListener('click', e => {
if(e.target.matches('.btn-decrease, .btn-decrease *')) {
    // Decrrease button is clicked
    if (state.recipe.servings > 1) {
         state.recipe.updateServings('dec');
         recipeView.updateServingsIngredients(state.recipe);
    }
} else if (e.target.matches('.btn-increase, .btn-increase *')) {
    // Increase button is clicked
    state.recipe.updateServings('inc');
    recipeView.updateServingsIngredients(state.recipe);
} else if (e.target.matches('.recipe__btn--add, .recipe__btn--add *')) {
    // Add ingredients to shopping list
    controlList();  <---------------- HERE
}

}); });

Holy molly guakamolly I found whats wrong.神圣的莫莉 guakamolly 我发现出了什么问题。 Turn out while importing functions from another file I didn't import correctly... (I mean everything *)从另一个文件导入函数时结果我没有正确导入......(我的意思是一切*)

暂无
暂无

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

相关问题 Uncaught typeError:无法读取未定义的属性-对象 - Uncaught typeError: Cannot read property of undefined - object 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined 未捕获的类型错误:无法读取 Object.onLoad 处未定义的属性“setAttribute” - Uncaught TypeError: Cannot read property 'setAttribute' of undefined at Object.onLoad Uncaught TypeError:无法读取未定义的属性“ canvas”-Javascript对象 - Uncaught TypeError: Cannot read property 'canvas' of undefined - Javascript Object js -Uncaught TypeError: Cannot read property 'x' of undefined at object (ball - js -Uncaught TypeError: Cannot read property 'x' of undefined at object (ball 未捕获的类型错误:无法读取 AJAX object 上未定义的属性“映射” - Uncaught TypeError: Cannot read property 'map' of undefined on AJAX object 未捕获的类型错误:无法读取未定义对象的属性“indexOf” - Uncaught TypeError: Cannot read property 'indexOf' of undefined with Object 未捕获的TypeError:无法读取对象中未定义的属性“样式” - Uncaught TypeError: Cannot read property 'style' of undefined in object 未捕获的TypeError:无法读取未定义的属性“数量” - Uncaught TypeError: Cannot read property 'quantity' of undefined 未捕获的TypeError:无法读取未定义的属性&#39;fromJSON&#39; - Uncaught TypeError: Cannot read property 'fromJSON' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM