2015-07-13 68 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)) 。 –