Answer the question
In order to leave comments, you need to log in
Sort the list by favorite, how to do it?
There is a list:
{
category: 'Посуда',
image: 'http://teadrinkers.org/assets/images/products/417/c2cee981a39099c7fa00c9c7797dfe7afae168fb.jpg',
title: 'Заголовок',
price: '10',
year: '2015',
country: 'Китай',
gram: false
},
{
category: 'Посуда',
image: 'http://teadrinkers.org/assets/images/products/354/42993ea70df676dfc302af7073b2503f581c2132.jpg',
title: 'Чашка глина (1)',
price: '500',
year: '2017',
country: 'Япония',
gram: false
},
{
category: 'Улун',
image: 'http://teadrinkers.org/assets/images/products/305/8386f5419680011666732dcf3a385a5c197d3ab9.png',
title: 'ГАБА улун полусферической скрутки',
price: '20',
year: '2002',
country: 'Китай',
gram: true
},
{
category: 'Красный чай',
image: 'http://teadrinkers.org/assets/images/products/433/34abe5f187227d79e0e8f7bb60711817072066f5.jpg',
title: 'Чжэн Хэ Сяо Чжун',
price: '22',
year: '2013',
country: 'Китай',
gram: true
}
cookie
or localStorage
list for example: "Red Tea, Oolong" and the list should be in this way first Red Tea > Oolong > everything else.
Answer the question
In order to leave comments, you need to log in
var list = [{
category: 'Посуда',
image: 'http://teadrinkers.org/assets/images/products/417/c2cee981a39099c7fa00c9c7797dfe7afae168fb.jpg',
title: 'Заголовок',
price: '10',
year: '2015',
country: 'Китай',
gram: false
},
{
category: 'Посуда',
image: 'http://teadrinkers.org/assets/images/products/354/42993ea70df676dfc302af7073b2503f581c2132.jpg',
title: 'Чашка глина (1)',
price: '500',
year: '2017',
country: 'Япония',
gram: false
},
{
category: 'Улун',
image: 'http://teadrinkers.org/assets/images/products/305/8386f5419680011666732dcf3a385a5c197d3ab9.png',
title: 'ГАБА улун полусферической скрутки',
price: '20',
year: '2002',
country: 'Китай',
gram: true
},
{
category: 'Красный чай',
image: 'http://teadrinkers.org/assets/images/products/433/34abe5f187227d79e0e8f7bb60711817072066f5.jpg',
title: 'Чжэн Хэ Сяо Чжун',
price: '22',
year: '2013',
country: 'Китай',
gram: true
}]
var data = 'Красный чай, Улун' //ваши данные из локалсторадж
var order = data.split(", ") //те же данные, но в массиве
var res = [] //сюда выводим
order.forEach(item => res.push(list.filter(l => l.category == item))) //данные по списку
res.push(list.filter(l => order.indexOf(l.category) == -1)) //все остальное
res = [].concat.apply([], res); //склеиваем
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question