-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw#3 #5
base: master
Are you sure you want to change the base?
Hw#3 #5
Conversation
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
//Все что смог сам реализовать. Не могу читать чужой код. Сразу становиться непонятно где что, кто что наследует и т.д. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В вашем коде главная проблема в том, откуда вы начали. Надо было начинать с определения класса корзины, попробовать получить товары корзины отрендерить их. Далее добавить обработчики на кнопки купить в каталоге и попробовать вызвать какой-нибудь метод карзины из них. Добавить метод добавления, подумать что ему должно приходить аргументом. Пробовать писать метод добавления и тд. То есть начать поэтапно реализовывать базовый функционал.
Сначала естественно будет непонятно - на это есть объяснения, ну и важно самостоятельно реализовывать, чтобы также формировать представление о том, что происходит, иначе чужой код вообще никак не понять.
rendered = false; | ||
|
||
constructor(product, img = 'https://placehold.it/200x150') { | ||
({ product_name: this.product_name, price: this.price, id_product: this.id } = product); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут должно быть id_product: this.id_product
|
||
render() { | ||
this.rendered = true; | ||
return `<div class="product-item"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
у блока потерялся data-id
render(){ | ||
this.rendered = true; | ||
return `<div class = "cart-item" data-id ="${this.id_product}"> | ||
<dic class ="product-bio"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Опечатка dic -> div
|
||
_init() { | ||
this.container.addEventListener('click',e =>{ | ||
if(e.target.classList.contains('.buy-btn')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Класс лист содержит строки с названием классов без точек - точка это селектор css. Поэтому не будет сейчас работать, чтобы заработало должно быть e.target.classList.contains('buy-btn')
} | ||
_init() { | ||
this.container.addEventListener('click',e =>{ | ||
if(e.target.classList.contains('.del-btn')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогичено кнопке купить - точку надо удалить
Пытался сделать самостоятельно. Но, все встало на передаче каких либо свойств из 1го класса в другой. Просто не понимаю что я не понимаю.....
Скопировал код из разбора ДЗ. И даже так все работает как то коряво и не правильно.