[英]JADE multi array
I have so many arrays and want to use it 我有很多数组,想使用它
- list = ['index1', 'index2', 'index3'];
- list2 = ['list2', 'list21', 'list22'];
each item in list
div #{item}
each item2 in list2
span #{item2}
but it compiled this: 但是它编译了这个:
index1list2list21list22
index2list2list21list22
index3list2list21list22
I want this result: 我想要这个结果:
index1list2
index2list21
index3list22
Are any solution for this? 有什么解决办法吗? Can jade do this? 玉能做到吗?
It seems like you want to iterate through list
and get the element at the same index in list2
. 似乎您想遍历list
并在list2
中的相同索引处获取元素。
What you probably want to do is something like the following: 您可能想做的事情如下所示:
- list = ['index1', 'index2', 'index3'];
- list2 = ['list2', 'list21', 'list22'];
each item, index in list
div #{item}
span #{item2[index]}
This will give you 这会给你
index1list2
index2list21
index3list22
You'll want to ensure that list.length = list2.length
and handle the case where they aren't (more specifically, when list.length > list2.length
). 您将要确保list.length = list2.length
并处理不存在的情况(更具体地说,当list.length > list2.length
)。 Otherwise, you'll likely get something like the following: 否则,您可能会得到类似以下内容的信息:
- list = ['index1', 'index2', 'index3', 'index4'];
- list2 = ['list2', 'list21', 'list22'];
each item, index in list
div #{item}
span #{item2[index]}
Result: 结果:
index1list2
index2list21
index3list22
index4undefined
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.