如何将嵌套的sass地图隔离到新地图中?例如,我有这样的sass地图:
$susy-setting: (
s: (
'columns': 4,
'gutters': 30px,
),
m: (
'columns': 8,
'gutters': 30px,
),
l: (
'columns': 12,
'gutters': 30px,
)
);
然后我需要在循环之后隔离每个地图,因为我的其他mixin需要映射其参数。
@each $setting in $susy-setting{
@include susy-settings-block($setting) { // This mixin need map
@for $i from 1 through map-get($setting, 'columns') {
@content;
}
}
}
答案 0 :(得分:0)
要回答您的主要问题,您需要同时获得循环中的键和值:@each $size, $setting in $susy-setting
。 $size
变量将存储密钥(例如s
,m
,l
),而$setting
变量存储分配给该密钥的地图值。
@mixin susy-settings-block(
$name,
$config: $susy-settings
) {
// store the old settings
$global: $susy;
// Get the new settings by name
$new: map-get($config, $name);
// apply the new settings
$susy: map-merge($susy, $new) !global;
// allow nested styles, using new settings
@content;
// return to the initial settings
$susy: $global !global;
}