Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 31.08.2019, 17:05
Аспирант
Отправить личное сообщение для nathan111777 Посмотреть профиль Найти все сообщения от nathan111777
 
Регистрация: 12.05.2019
Сообщений: 44

Как переделать cart.js(отдельная корзина)? Что в нем изменить чтобы все работало?
У меня есть проект. Который добавляет товары в корзину и фильтрует товары по цене, стране, размере ...
Вот этот проект:

https://codesandbox.io/s/great-bardeen-p7v7f

В этом проекте есть файл eshop.js, что он делает:
1) выводит товары на страницу man.html или woman.html из файла goods.json
2) добавляет товары в мини корзину (на той же странице)

а также файл cart.js что он делает:
1) он отображает товары на странице cart.html что добавлены в мини корзину
2) можно на странице cart.html добавлять или удалять товары.

Но мне было нужно добавить в eshop.js фильтр товаров который фильтрует товары по различным свойствам объектов находящихся в файле goods.json, а также фильтр что отображает товары в зависимости на которую html страницу зашли или man.html или woman.html. Нашел в интернете такой фильтр но пришлось полностью переделать файл eshop.js и после этого cart.js перестал работать и на отдельной странице корзины(cart.html) уже не отображаются добавленые в мини корзину товары.Его нужно переделать как-то но я не знаю как, я новичок в JavaScript. Даже не представляю как это сделать....
Вот так должно выглядеть отображение на странице cart.html после того как cart.js будет редактировано:

http://i.piccy.info/i9/fab9a0f92b65e...334636/sk2.jpg

Как переделать cart.js? Что в нем изменить чтобы все работало?

Последний раз редактировалось nathan111777, 31.08.2019 в 17:11.
Ответить с цитированием
  #2 (permalink)  
Старый 01.09.2019, 23:08
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

Мне кажется надо в объектной парадигме писать, т.е. определить абстракции (Витрина, Корзина, ...), их интерфейсы (наборы методов), типа так:
var cart = {
    items: [],
    add: function (item) {},
    remove: function (item) {},
};

Небольшой ликбез, "C++ Primer" (3rd edition, Lippman & Lajoie):
Цитата:
[Algorithms + Data = Program]
There are two primary aspects to the programs we write.
1. A collection of algorithms (that is, the programmed instructions to solve a particular task).
2. A collection of data against which the algorithms are run to provide each unique solution.
[Algorithms ~ Data = Paradigm]
These two primary program aspects, algorithms and data, have remained invariant throughout the short history of computing. What has evolved is the relationship between them. This relationship is spoken of as a programming paradigm.
[Procedural-Based Programming]
In the procedural programming paradigm, a problem is directly modeled by a set of algorithms. A check-out/check-in system for loan materials of a public library, such as books, videos, and so on, is represented as a series of procedures, the two central procedures being the checking-out and checking-in of library materials. The data is stored separately, accessed either at a global location or by being passed into the procedures. [...] Individual procedures, such as check_in(), check_out(), overdue(), fine(), and so on, are referred to as functions. [...]
[Object-Based Programming]
In the 1970s, the focus of program design shifted from the procedural paradigm to that of abstract data types (now generally referred to as object-based programming). In this paradigm, a problem is modeled by a set of data abstractions. [...] we refer to these abstractions as classes. Our library check-out system, for example, under this paradigm is represented as the interaction between object instances of classes such as Book, Borrower, DueDate (an aspect of Time), and the inevitable Fine (an aspect of Money), representing the library abstractions. The algorithms associated with each class are referred to as the class's public interface. The data is privately stored within each object; access of the data is hidden from the general program. [...]
[Object-Oriented Programming]
Object-oriented programming extends abstract data types through the mechanisms of inheritance (a "reuse" of an existing implementation) and dynamic binding (a reuse of an existing public interface). Special type/subtype relationships between previously independent types are now provided. A book, videotape, recording, and children's puppet are each a kind of library material, although each has its own check-out and check-in policy. The shared public interface and private data are placed in an abstract LibraryMaterial class. Each specific library material class inherits the shared behavior from the LibraryMaterial abstract class and need provide only the algorithms and data that support its behavior. [...]
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Открытие div блока при первом визите на сайт Nushaba Общие вопросы Javascript 28 20.12.2013 21:24
Решение проблемы кодировок для AJAX и PHP без iconv (cp1251 в AJAX) Serge Ageyev AJAX и COMET 10 24.04.2013 20:48
Название ячейки таблицы Questioner Общие вопросы Javascript 6 16.02.2011 09:58
Разбираем AjaxOOP eai Общие вопросы Javascript 41 04.11.2010 23:37
глюк форума Gvozd Сайт Javascript.ru 11 18.03.2009 14:37