[英]Isolate nested sass map into new map
如何將嵌套的Sass貼圖隔離到新貼圖中? 例如我有這樣的sass map:
$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;
}
}
}
要回答您的主要問題,您需要在循環中同時獲取鍵和值: @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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.