简体   繁体   English

for循环在更少的css mixin中不起作用

[英]for loop not working in less css mixin

I have noticed that a piece of Less I thought was working as expected is not actually generating all the styles I need - my for loop is not working. 我注意到,我以为正在工作的Less片段实际上并没有生成我需要的所有样式-我的for循环不起作用。

The less in question is: 问题较少的是:

.for(@list, @code) {
    & {
        .loop(@i:1) when (@i =< length(@list)) {
            @value: extract(@list, @i);

            @code();

            .loop(@i + 1);
        }

        .loop();
    }
}

.role-variants(@variants, @props){
    .for(@variants, {
      .security_class_@{value} {
        @props();
      }
    });
}

@admin-roles: admin, admin_manager, admin_user, admin_manager_user;

html{
    body{
        &.admin{
            .role-variants(@admin-roles, {display: block;});
        }
    }
}

on http://less2css.org/ this compiles correctly, generating the classes I expect. http://less2css.org/上可以正确编译,生成我期望的类。

When I compile locally, I only get the following class: 在本地编译时,只会得到以下类:

html body.admin .security_class_admin {
    display: block
}

My for loop is not working locally, though it seems to be valid and working using the less compiler. 我的for循环在本地不起作用,尽管它似乎是有效的,并且使用了较少的编译器。 Any ideas on how I can modify it to work locally, or perhaps I need to update my environment to a specific version, though it seems to be up to date. 关于如何修改它以在本地工作的任何想法,或者也许我需要将环境更新为特定版本,尽管它似乎是最新的。

Thanks again for your help. 再次感谢你的帮助。

Jamie 杰米

my loop was malformed - this loop now works as expected: 我的循环格式错误-该循环现在可以正常运行:

.for(@list, @code) {
    & {
        .loop(@i) when (@i > 0) {
            @value: extract(@list, @i);
            @code();
            .loop((@i - 1));
        }
        .loop(length(@list));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM