1 回答
TA贡献1887条经验 获得超5个赞
您需要一个过滤功能来考虑所有可用的过滤器。像这样的东西:
if (scope=="subsequent") {
const defaultLocation = "Localization...";
const defaultEvent = "Event...";
const defaultDate = "";
// Remove photos that were already there
while (previewBox.lastElementChild) {
previewBox.removeChild(previewBox.lastElementChild);
}
// Getting data from the select fields and date picker
let selectedLocation = locationSelector.options[locationSelector.selectedIndex].text;
let selectedEvent = eventSelector.options[eventSelector.selectedIndex].text;
let selectedDate = dateSelector.value
for (let i = 0; i < currentPhotos.length; i++) {
let currentPicture = currentPhotos[i];
// This is currently doing nothing, it's just my way of knowing if the select fields
// and date picker have been selected or are in their default values:
if (selectedLocation != "Localization..." || selectedEvent != "Event..." || selectedDate != "" ) {
console.log("selected!")
}
if((selectedLocation == defaultLocation || currentPicture.location == selectedLocation) &&
(selectedEvent == defaultEvent || currentPicture.event == selectedEvent) &&
(selectedDate == defaultDate || currentPicture.date == selectedDate)) {
let newDiv = document.createElement("div");
let newImg = document.createElement("img");
// From here on it's simply adding the pictures to the preview box
newImg.setAttribute("src", currentPhotos[i].path);
newImg.addEventListener("click", openPhotoViewer)
newDiv.appendChild(newImg)
previewBox.appendChild(newDiv)
}
}
}
添加回答
举报