【发布时间】:2022-01-15 21:23:21
【问题描述】:
我正在尝试在 Pug 中使用“Json”“创建”一个模板,但有一点我需要放置大量信息。但对我来说,问题变成了我需要深入阅读一个元素的地方。
-
var SuperSlidersInfo = {
'numero': '4',
'sectionName': 'Dignidad',
'video': true,
'youtube': [
'idVideo',
'idVideo2',
],
'notes':[
['prueba1', 'prueba2'],
['segundo1', 'segundo2', 'segundo3'],
],
'img': [
'NombreImagen',
'NombreImagen2',
],
'extension': 'jpg',
'titulo': [
'Titulo',
],
'parrafo': [
'Texto',
]}
+SuperSlidersPug(SuperSlidersInfo)
mixin SuperSlidersPug(SuperSlidersInfo)
.container-pc
.container-sliderAutomatico.no-phone
div(id=`sliderAutomatico${SuperSlidersInfo.numero}` class= SuperSlidersInfo.video ? "dosVideos-container" : "otraCosa").sliderAutomatico
each imgName, index in SuperSlidersInfo.img
//- div(class= SuperSlidersInfo.video ? "dosVideos").sliderAutomatico__section
div(class= SuperSlidersInfo.video ? "dosVideos" : "otraCosa").sliderAutomatico__section
.swiper-content
if SuperSlidersInfo.video
.section_videoContainer
a(href=`#video${SuperSlidersInfo.sectionName}${index}`).section_videoThumbnail--Container
img(src=`${imgURL}${SuperSlidersInfo.sectionName}${index + 1}.${SuperSlidersInfo.extension}`, alt="")
h3.swiper-content_titulo= `${SuperSlidersInfo.titulo[index]}`
.section_video--notes
//- -----------------
//- Problem
//- -----------------
//- the "a" below works, but I need to "create" and each, or for, or any loop for to put all the elements in that especific array.
//- a(href=`${SuperSlidersInfo.notes[index]}`).section_video--note
//- The "each" below it suppose to works. But when I put the "[index]" it brokes..
each note, noteIndex in SuperSlidersInfo.notes[index]
a(href=`${note}`).section_video--note
对于一般元素,它运作良好。但是当我需要阅读“笔记”时。这对我来说是不可能的。
但是当我输入each note, noteIndex in SuperSlidersInfo.notes[index] 时,一切都坏了......
所以我需要读取“note”在其数组中的“元素”...
//- Works well
each note, noteIndex in SuperSlidersInfo.notes
//- Or...
each note, noteIndex in SuperSlidersInfo.notes[0]
//- But if I put this It's Broke (And I thought that could works well)
each note, noteIndex in SuperSlidersInfo.notes[index]
index 来自几乎存在于代码顶部的each。
我怎么说,它是一个“模板”,所以有时我不知道可能存在多少个“项目”。所以我需要为所有可能存在的元素使用each...
【问题讨论】:
标签: javascript arrays json oop pug