2015-07-13 50 views
1

我需要的變量name更改爲treesballoons等在一個循環,以獲得在一個循環改變的變量名

.trees{ color:1;} 
.balloons { color:2;} 

,但我得到相反:

.trees{color:2} 
.name{color:1} 

試過這種混入但沒有工作,我做錯了什麼?

@name:name; 
.name(@index) when (@index = 2) {@name: balloons;} 
.name(@index) when (@index = 1) {@name: trees;} 
.name(@index) when (@index > 0) { 
[email protected]{name}{ color:@index; } 
    .name(@index - 1) 
} 
.name(2); 

回答

2

看看這個codepen,你必須使用所需的名稱list,您可以通過它獲取列表中的任何元素的索引:

@item: extract(@names, @index); 
+0

尼斯和問題的最佳解決方案:) – Harry

+0

感謝幫助dajnz – thenine

+0

儘管將整個代碼片段包含到答案中也很方便(畢竟它只是[幾行代碼](https://gist.github.com/seven-phases-max/14a2e640cf20897e27f8)) 。 –