質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

0回答

556閲覧

TypeError: Cannot read property 'count' of undefined

21212121

総合スコア61

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2019/11/20 11:42

recipeView.js import{elements} from './base'; const createIngredient = ingredient => ` <li class="recipe__item"> <svg class="recipe__icon"> <use href="img/icons.svg#icon-check"></use> </svg> <div class="recipe__count">${ingredient.count}</div> <div class="recipe__ingredient"> <span class="recipe__unit">${ingredient.unit}</span> ${ingredient.ingredient} </div> </li> `; export const renderRecipe = recipe => { const markup = ` <figure class="recipe__fig"> <img src="${recipe.img}" alt="${recipe.title}" class="recipe__img"> <h1 class="recipe__title"> <span>${recipe.title}</span> </h1> </figure> <div class="recipe__details"> <div class="recipe__info"> <svg class="recipe__info-icon"> <use href="img/icons.svg#icon-stopwatch"></use> </svg> <span class="recipe__info-data recipe__info-data--minutes">${recipe.time}</span> <span class="recipe__info-text"> minutes</span> </div> <div class="recipe__info"> <svg class="recipe__info-icon"> <use href="img/icons.svg#icon-man"></use> </svg> <span class="recipe__info-data recipe__info-data--people">${recipe.servings}</span> <span class="recipe__info-text"> servings</span> <div class="recipe__info-buttons"> <button class="btn-tiny"> <svg> <use href="img/icons.svg#icon-circle-with-minus"></use> </svg> </button> <button class="btn-tiny"> <svg> <use href="img/icons.svg#icon-circle-with-plus"></use> </svg> </button> </div> </div> <button class="recipe__love"> <svg class="header__likes"> <use href="img/icons.svg#icon-heart-outlined"></use> </svg> </button> </div> <div class="recipe__ingredients"> <ul class="recipe__ingredient-list"> ${recipe.ingredients.map(el => createIngredient(el)).join('')} </ul> <button class="btn-small recipe__btn"> <svg class="search__icon"> <use href="img/icons.svg#icon-shopping-cart"></use> </svg> <span>Add to shopping list</span> </button> </div> <div class="recipe__directions"> <h2 class="heading-2">How to cook it</h2> <p class="recipe__directions-text"> This recipe was carefully designed and tested by <span class="recipe__by">${recipe.author}</span>. Please check out directions at their website. </p> <a class="btn-small recipe__btn" href="${recipe.url}" target="_blank"> <span>Directions</span> <svg class="search__icon"> <use href="img/icons.svg#icon-triangle-right"></use> </svg> </a> </div> `; elements.recipe.insertAdjacentHTML('afterbegin', markup); };
index.js import Search from './models/Search'; import Recipe from './models/Recipe'; import * as searchView from './views/searchView'; import * as recipeView from './views/recipeView'; import { elements, renderLoader, clearLoader, } from './views/base'; /** Global state of the app * - search object * - Current recipe object * - shopping list object * - Liked recipes */ const state = {}; const controlSearch = async () => { // 1) Get query from view const query = searchView.getInput(); if (query) { //2) New search object and add to state state.search = new Search(query); //3) Prepare UI for results searchView.clearInput(); searchView.clearResults(); renderLoader(elements.searchRes); try { //4) Search for recipes await state.search.getResults(); //5) Render results on UI clearLoader(); searchView.renderResults(state.search.result); }catch(err){ alert('Something wrong with the search...'); clearLoader(); } } } elements.searchForm.addEventListener('submit', e => { e.preventDefault(); controlSearch(); }); //TESTING elements.searchResPages.addEventListener('click', e => { const btn = e.target.closest('.btn-inline'); if (btn) { const goToPage = parseInt(btn.dataset.goto, 10); searchView.clearResults(); searchView.renderResults(state.search.result, goToPage); console.log(goToPage); } }); /** * RECIPE CONTROLLER */ const controlRecipe = async () => { //get ID from url const id = window.location.hash.replace('#', ''); console.log(id); if (id) { // Prepare UI for changes renderLoader(elements.recipe); // Create new recipe object state.recipe = new Recipe(id); //Testing try { // Get recipe date and parse await state.recipe.getRecipe(); state.recipe.parseIngredients(); // Calculate servings and time state.recipe.calcTime(); state.recipe.calcServings(); //Render recipe clearLoader(); recipeView.renderRecipe(state.recipe); } catch (err) { console.log(err); } } }; // window.addEventListener('hashchange' ,controlRecipe); // window.addEventListener('load' ,controlRecipe); ['hashchange', 'load'].forEach(event => window.addEventListener(event, controlRecipe));
base.js```ここに言語を入力 export const elements = { searchForm: document.querySelector('.search'), searchInput: document.querySelector('.search__field'), searchRes: document.querySelector('.results'), searchResList: document.querySelector('.results__list'), searchResPages: document.querySelector('.results__pages'), recipe: document.querySelector('.recipe') }; export const elementStrings = { loader: 'loader' }; export const renderLoader = parent => { const loader = ` <div class="${elementStrings.loader}"> <svg> <use href= "img/icons.svg#icon-cw"></use> </svg> </div> `; parent.insertAdjacentHTML('afterbegin', loader); }; export const clearLoader = () => { const loader = document.querySelector(`.${elementStrings.loader}`); if (loader) loader.parentElement.removeChild(loader); };

現在Udmeyの動画で作業を進めているのですが、TypeError: Cannot read property 'count' of undefined のエラーに直面してしまいました。

お手数ですがご教授いただけると幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2019/11/21 00:14

これ本当に単なるJavaScriptですか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問