У меня есть функция, которая получает данные из файла geojson и сортирует их по алфавиту в одном поле.
Однако, вместо того, чтобы отсортировать и поместить его в один блок, я бы хотел разбить результаты на атрибут с уникальным значением 12, называемым Project_Year, с понижением от самого последнего к последнему.
Вот что у меня есть.Это имеет функцию сортировки, которая работает, и она также успешно извлекает из файла JSON.
function buildLocationList(features) {
var listings = document.getElementById('listings');
listings.innerHTML = '';
// Iterate through the list of stores
if(features.length > 0){
// allowed me to sort here from my list
var sortedFeatures = features.sort(function(a,b){
if(a.properties.Project_Name < b.properties.Project_Name) {return -1}
if(a.properties.Project_Name > b.properties.Project_Name) {return 1 }
return 0;
})
sortedFeatures.forEach(function(feature, i){
var currentFeature = feature;
// Shorten data.feature.properties to just `prop` so we're not
// writing this long form over and over again.
var prop = currentFeature.properties;
// Select the listing container in the HTML and append a div
// with the class 'item' for each store
var listing = document.createElement('div')
listing.className = 'item';
listing.id = 'listings' + i;
// Create a new link with the class 'title' for each store
// and fill it with the store address
var link = document.createElement('a');
link.href = '#';
link.className = 'title';
link.dataPosition = i;
link.innerHTML = prop.Project_Name;
Нужно ли создавать новую коробку css в качестве контейнера, который получает уникальные функции Project_Year из файла geojson?
Или я могу просто написать функцию, которая может в алфавитном порядке просто размещать все, где она должна находиться, показывая год в качестве заголовка?