首页 > 解决方案 > 减:不能在每个内部使用 Map

问题描述

我有以下更少:

@threshold:{
  a:50;
  b:200;
};

@themes:{
  a:red;
  b:blue;
};

.mymixin(@name,@color,@thrshld){
  //do-something
}

each(@themes,{
  .mymixin(@key,@value,@threshold[@key]);
});

通过运行代码,出现以下错误:

RuntimeError:错误评估函数each:未找到变量@key...

我正在使用 v3.9.0

如何在每个功能中使用地图?

标签: cssless

解决方案


您需要使用@map[$@property]语法来评估@map[@property]

.mymixin(@name, @color, @thrshld) {
  .theme-@{name} {
    color: @color;
    width: @thrshld;
  }
}

@threshold: {
  a: 50;
  b: 200;
};

@themes: {
  a: red;
  b: blue;
};

each(@themes, {
  .mymixin(@key, @value, @threshold[$@key])
})

推荐阅读