Answer the question
In order to leave comments, you need to log in
How is it easier and more correct to store and retrieve json data?
At one time I used two options with storing json data, in a variable
var storage = JSON.parse(`{
"id": "4",
"name": "Товар 4",
"price": "2500"
}'
<% _.each(goods, function(good) { %>
<div class="basket-item js-cart-item" data-id="<%= good.id %>">
<div class="basket_item__image-link"></div>
<div class="basket-item__main-title"><%- good.name %></div>
<div class="page__basket-line"></div>
<div class="price_theme_basket-item"><span class="price__item"><%= good.price %></span> руб.</div>
<div class="cart-clicker">
<div class="input-quantity__button input-quantity__inc js-change-count"
title="Увеличить на 1"
data-id="<%= good.id %>"
data-delta="1">
</div>
<div class="input-quantity__val">
<input class="input-quantity__val-input js-count" type="text" value="<%= good.count %>">
</div>
<div class="input-quantity__button input-quantity__dec js-change-count"
title="Уменьшить на 1"
data-id="<%= good.id %>"
data-delta="-1">
</div>
</div>
<div class="page__basket_min-line"></div>
<div class="basket-item__main-delete js-remove-from-cart" data-id="<%= good.id %>">Убрать</div>
</div>
<% }); %>
'use strict';
// Модуль каталога
var catalog = (function($) {
// Инициализация модуля
function init() {
_render();
}
function init_six() {
_renders();
}
// Рендерим каталог
function _render() {
var template = _.template($('#catalog-template').html()),
$goods = $('#js-catalogue-list');
$.getJSON('data/goods.json', function(data) {
$goods.html(template({goods: data}));
});
}
// Экспортируем наружу
return {
init: init,
init_six: init_six
}
function _renders() {
var template = _.template($('#catalog-template').html()),
$goods = $('#js-load-catalogue');
$.getJSON('data/six.json', function(data) {
$goods.html(template({goods: data}));
});
}
})(jQuery);
Answer the question
In order to leave comments, you need to log in
too general question. even the template engine is incomprehensible.
and in general your example is written as
var storage = {
"id": "4",
"name": "Товар 4",
"price": "2500"
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question