好的。所以,這個問題是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