Skip to content

задание 1 и 2#4

Open
ArchibaldovRPtech wants to merge 1 commit intomainfrom
lesson3
Open

задание 1 и 2#4
ArchibaldovRPtech wants to merge 1 commit intomainfrom
lesson3

Conversation

@ArchibaldovRPtech
Copy link
Copy Markdown
Owner

No description provided.

Comment thread js/main.js
Comment on lines +18 to +32
let getData = (url) => {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status !== 200) {
reject('error');
} else {
resolve(xhr.responseText);
}
}
}
})
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, все верно, первое задание реализовано правильно

Comment thread js/main.js

}
// id получаем от кнопки купить товар
addPurchasedProduct(id, productsList) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что за продактс лист попадает в метод? Надо ли это? Может просто все данные по товару сразу отправить, не только id (из кнопки мы все можем вытащить, если добавим ей соответствующие data атрибуты)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я думал вызывать этот метод из обработчика событий клика по кнопке, и передавать массив products из класса productsList

Comment thread js/main.js

deletePurchasedProduct(id) {
let removableInd = purchasedProducts.findIndex(product => product.id === id);
if (removableInd != -1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!== пишите строгие сравнения

Comment thread js/main.js
deletePurchasedProduct(id) {
let removableInd = purchasedProducts.findIndex(product => product.id === id);
if (removableInd != -1) {
this.purchasedProducts.splice(removableInd, 1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отлично, так удалим товар, но помимо этого еще страницу надо обновить и отобразить обновления

Comment thread js/main.js
if (id === product.id) {
const purchasedProduct = new PurchasedProduct(product);
this.purchasedProducts.push(purchasedProduct);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Товар добавлен, но надо теперь отобразить его - тут видимо рендер надо вызывать

Comment thread js/main.js
// render() html код
}


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как набросок корзины - очень хорошо, придраться не к чему. Надо продолжать доделывать. Если застряли - пишите, что не получается, разберемся

Copy link
Copy Markdown

@AndrewRimsky AndrewRimsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все отлично!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants