admin管理员组文章数量:1289586
I can't find in the docs an example of using arrays as variables. It would be obvious though to have arrays support so I suspect I should search for that in a different way.
I have found lists, but not sure if these are intended for the same or similar purpose as arrays and couldn't find syntax and examples.
I have a list of colors
- cards_colors = #E0137E #8431BF #2388C4 #FED462 #EC633B #B3CF32 #2388C4 #EA8527
And I want to assign each color to a respective element in a loop, similar to this:
for num in (0..10)
&.card-{num}
background cards_colors[{num}]
I can't find in the docs an example of using arrays as variables. It would be obvious though to have arrays support so I suspect I should search for that in a different way.
I have found lists, but not sure if these are intended for the same or similar purpose as arrays and couldn't find syntax and examples.
I have a list of colors
- cards_colors = #E0137E #8431BF #2388C4 #FED462 #EC633B #B3CF32 #2388C4 #EA8527
And I want to assign each color to a respective element in a loop, similar to this:
for num in (0..10)
&.card-{num}
background cards_colors[{num}]
Share
Improve this question
edited Jan 29, 2014 at 17:37
Sergei Basharov
asked Jan 29, 2014 at 17:30
Sergei BasharovSergei Basharov
53.9k78 gold badges207 silver badges352 bronze badges
1
- learnboost.github.io/stylus/docs/iteration.html – Hackerman Commented Jan 29, 2014 at 17:34
3 Answers
Reset to default 6using a list works for me:
cards_colors = ( #E0137E #8431BF #2388C4 )
for num in (0..2)
.card-{num}
background cards_colors[num]
see demo: http://codepen.io/anon/pen/IeiEw
Stylus does support arrays, but it's hard to find in their documentation, even after they revamped it
$arrayName = value0, value1, value2
$arrayName[1] //value1
With using range()
cards_colors = ( #E0137E #8431BF #2388C4 )
for num in range(0,(length(cards_colors) - 1))
.card-{num}
background cards_colors[num]
本文标签: javascriptDoes Stylus support arrays of variablesStack Overflow
版权声明:本文标题:javascript - Does Stylus support arrays of variables? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741402307a2376740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论