好的。所以,这个问题是the duplicate I mentioned唯一的--主要是因为循环中有2个数组。您可能需要重新命名该问题以备将来搜索。
首先关闭,我花了很长时间才意识到需要认真对待错误信息。在你的情况 - 它告诉你有括号 - 并且不应该 - 所以他们是意外的。删除它们。手写笔的语法大部分与SCSS类似 - 您只需输入较少的内容即可 - 并确保您的缩进是完美的。在阐明规则的开始和结束时,缩进代替括号。删除所有括号 - 和分号。 *(附注 - 使用$ VAR变量/他们很可能会被要求后 - 也 - :
曾经是一个选择 - 他们也将被要求)
二,我猜,这for
循环就像Javascript中的每个循环,因此您可以使用逗号分隔列表获取currentvalue, currentIndex, fullArray
参数。 (我不是100%,这是)
for fillColor, currentIndex in $fillColorArray
这将允许您访问颜色和它的这些占位符索引。
这里是活着的例子:https://codepen.io/sheriffderek/pen/64c6791116c3a180cb196610f9962f17/ - 你可以选择在手写笔窗格的小箭头图标中查看已编译的CSS。
标记
<ul class="chart-list one">
<li class="chart">
<span>Chart 1</span>
</li>
<li class="chart">
<span>Chart 2</span>
</li>
<li class="chart">
<span>Chart 3</span>
</li>
<li class="chart">
<span>Chart 4</span>
</li>
</ul>
...
你可以做到这一点的几种方法 - 根据不同的应用。这里有一个2个循环的例子 - 另一个循环只有一个。
笔
$fillColorArray = (#f06 pink)
$textColorArray = (white #f06)
remove-list-styles()
list-style: none
margin: 0
padding: 0
.chart-list
remove-list-styles()
margin-bottom: 2rem
background: lightgray
.chart
padding: 1rem
.chart-list.one
//
.chart
//
for fillColor, currentIndex in $fillColorArray
&:nth-of-type({currentIndex + 1})
background: fillColor
for textColor, currentIndex in $textColorArray
&:nth-of-type({currentIndex + 1})
span
color: textColor
.chart-list.two
//
.chart
//
for fillColor, currentIndex in $fillColorArray
&:nth-of-type({currentIndex + 1})
background: fillColor
span
color: $textColorArray[currentIndex]
// &:nth-of-type(2n + {currentIndex + 1})
// if you want it to repeat at those intervals
.chart-list.three
//
.chart
//
for fillColor, currentIndex in $fillColorArray
&:nth-of-type(2n + {currentIndex + 1})
background: fillColor
span
color: $textColorArray[currentIndex]
可能重复? http://stackoverflow.com/questions/34410889/stylus-iteration-interpolation-with-nth-of-type – sheriffderek
即使重复,答案也不适合我。 – user776686