将获取的值转换为变量,以便可以控制到达数据时遇到问题。
HTML:
$itemicon-ca: "\a100";
$itemicon-star: "\a101";
$itemicon-pin: "\a102";
$itemicon-collection: ('ca', 'star', 'pin');
@for $i from 0 to length($itemicon-collection) {
$name: nth($itemicon-collection, $i+1);
$value: itemicon-#{$name};
.itemicon-#{$name} {
&:before {
content: #{$value};
}
}
}
当前打印此:
.itemicon-ca:before {
content: itemicon-ca;
}
.itemicon-star:before {
content: itemicon-star;
}
.itemicon-pin:before {
content: itemicon-pin;
}
想法是将生成的值转换为变量,以便您可以打印数据
我应该打印这个:
.itemicon-ca {
&:before {
content: $itemicon-ca;
}
}
.itemicon-star {
&:before {
content: $itemicon-star;
}
}
.itemicon-pin {
&:before {
content: $itemicon-pin;
}
}
有什么想法或建议找到可能的解决方案吗?
答案 0 :(得分:0)
您无法在applicationVariants.all { variant ->
variant.outputs.all {
def flavor = variant.name
def versionName = variant.versionName
outputFileName = "prefix_${flavor}_${versionName}.apk"
}
}
中动态调用变量。但是,您可以使用地图和SASS
循环来实现所需的目标:
@each
您可以检查this以获得有关$itemicon-collection: (
'ca' : "\a100",
'star' : "\a101",
'pin' : "\a102"
);
@each $name, $value in $itemicon-collection {
.itemicon-#{$name} {
&:before {
content: #{$value};
}
}
}
循环的更多信息。