ขอขอบคุณสำหรับความช่วยเหลือของคุณ รวมถึง for-in loop ที่ฉันได้เรียนรู้จากโพสต์ต่อไปนี้: วิธีสร้าง CSS ด้วยการวนซ้ำในเวลาน้อยลง
ตอนนี้ฉันมี:
.for(@list, @code) {
& {
.loop(@i:1) when (@i =< length(@list)) {
@value: extract(@list, @i);
@code();
.loop(@i + 1);
}
.loop();
}
}
.role-varients(@orgType, @variants, @props, @type:child){
.for(@variants, {
& when (@type = append) {
&.@{orgType}.security_class_@{value} {
@props();
}
}
& when not (@type = append) {
.@{orgType}.security_class_@{value} {
@props();
}
}
});
}
@admin-roles: admin, admin_manager, admin_user, admin_manager_user;
@manager-roles: manager, admin_manager, manager_user, admin_manager_user;
@user-roles: user, admin_user, manager_user, admin_manager_user;
&.service_provider{
&.admin{
.role-varients(service_provider, @admin-roles, {display: block;});
th{
.role-varients(service_provider, @admin-roles, {display: table-cell;}, append);
}
button{
.role-varients(service_provider, @admin-roles, {display: inline-block;}, append);
}
}
&.manager{
.role-varients(service_provider, @manager-roles, {display: block;});
th{
.role-varients(service_provider, @manager-roles, {display: table-cell;}, append);
}
button{
.role-varients(service_provider, @manager-roles, {display: inline-block;}, append);
}
}
&.user{
.role-varients(service_provider, @user-roles, {display: block;});
th{
.role-varients(service_provider, @user-roles, {display: table-cell;}, append);
}
button{
.role-varients(service_provider, @user-roles, {display: inline-block;}, append);
}
}
}
&.client{
&.admin{
.role-varients(client, @admin-roles, {display: block;});
th{
.role-varients(client, @admin-roles, {display: table-cell;}, append);
}
button{
.role-varients(client, @admin-roles, {display: inline-block;}, append);
}
}
&.manager{
.role-varients(client, @manager-roles, {display: block;});
th{
.role-varients(client, @manager-roles, {display: table-cell;}, append);
}
button{
.role-varients(client, @manager-roles, {display: inline-block;}, append);
}
}
&.user{
.role-varients(client, @user-roles, {display: block;});
th{
.role-varients(client, @user-roles, {display: table-cell;}, append);
}
button{
.role-varients(client, @user-roles, {display: inline-block;}, append);
}
}
}
&.vendor{
&.admin{
.role-varients(vendor, @admin-roles, {display: block;});
th{
.role-varients(vendor, @admin-roles, {display: table-cell;}, append);
}
button{
.role-varients(vendor, @admin-roles, {display: inline-block;}, append);
}
}
&.manager{
.role-varients(vendor, @manager-roles, {display: block;});
th{
.role-varients(vendor, @manager-roles, {display: table-cell;}, append);
}
button{
.role-varients(vendor, @manager-roles, {display: inline-block;}, append);
}
}
&.user{
.role-varients(vendor, @user-roles, {display: block;});
th{
.role-varients(vendor, @user-roles, {display: table-cell;}, append);
}
button{
.role-varients(vendor, @user-roles, {display: inline-block;}, append);
}
}
}
ฉันจะใช้ for loop อันอื่นเพื่อจัดการ 3 บล็อกหลัก [service_provider, client, vendor] แต่ที่ฉันใช้ .@{value} ฉันเดาว่าขอบเขตใช้งานไม่ได้จากการมีลูปภายในลูปและมันไม่ได้ให้ผลลัพธ์ที่คาดหวัง .
แม้ว่าข้อความข้างต้นจะดูยาว แต่ก็ดีกว่าการเขียนกฎแต่ละข้อด้วยตนเองอย่างแน่นอน
วิธีแก้ปัญหาของฉันเกิดจากการป้อนข้อมูลของ Harry ดังนั้นฉันเดาว่าฉันควรทำเครื่องหมายคำตอบของเขาว่าถูกต้องหรือไม่ ขอบคุณทุกคนอีกครั้ง;)
person
user2115620
schedule
13.06.2016