Less:不能在每个内部使用 Map

Less: Can't use Map inside each

我少关注:

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

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

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

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

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

RuntimeError: error evaluating function each: variable @key not found...

我正在使用 v3.9.0

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

您需要使用 @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])
})