Jak mogę wyizolować zagnieżdżoną mapę sass na nowej mapie? Na przykład mam taką mapę sass:
$susy-setting: (
s: (
"columns": 4,
"gutters": 30px,
),
m: (
"columns": 8,
"gutters": 30px,
),
l: (
"columns": 12,
"gutters": 30px,
)
);
Następnie muszę wyizolować każdą mapę wewnątrz po pętli, ponieważ moja inna mieszanka potrzebuje mapy dla swojego parametru.
@each $setting in $susy-setting{
@include susy-settings-block($setting) { // This mixin need map
@for $i from 1 through map-get($setting, "columns") {
@content;
}
}
}
Odpowiedzi:
0 dla odpowiedzi № 1Aby odpowiedzieć na podstawowe pytanie, musisz uzyskać klucz i wartość w pętli: @each $size, $setting in $susy-setting
. The $size
zmienna zapisze klucz (np. s
, m
, l
) podczas, gdy $setting
zmienna przechowuje wartość mapy przypisaną do tego klucza.
EDYCJA: Widziałem twój komentarz na mojej liście, który zapewnia nieco więcej kontekstu. Spróbuj tego:
@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;
}