2016-09-27 19 views
1

這是我的循環:LESS環路誤差3

@loop-start: 1; 
@loop-end: 20; 
.loop(@n, @i) when (@n =< @loop-end) { 
    .testi-square:nth-of-type(@{n}) {order: (@i);} 
    .testi-square:nth-of-type(@{n + 1}) {order: (@i + 1);} 
    .testi-square:nth-of-type(@{n + 2}) {order: (@i + 2);} 

    .loop((@n + 3), (@i + 6)); // next iteration 
} 
.loop(@loop-start, @loop-start); // launch the loop 

這是錯誤我得到:

Running "less:compileThemeWeb" (less) task 
ParseError: Missing closing ')' in less/theme-web.less on line 3630, column 29: 
3629 .testi-square:nth-of-type(@{n}) {order: (@i);} 
3630 .testi-square:nth-of-type(@{n + 1}) {order: (@i + 1);} 
3631 .testi-square:nth-of-type(@{n + 2}) {order: (@i + 2);} 
Warning: Error compiling less/theme-web.less Use --force to continue. 

Aborted due to warnings. 

我使用的是最新的引導創建我的主題。我在過去的6個月裏一直在使用它,沒有任何問題,我懷疑LESS的版本太舊了。不知道如何解決這個問題,看起來像一個語法的東西,但不知道。一整天都在盯着http://lesscss.org/features/#loops-feature,在網上衝浪,但沒有骰子。

+0

'n-type-type(@ {n + 1})' - 這是無效的較少的代碼。你不能使用表達式或任何其他的東西(函數調用等),只有純變量例如'@ {n}'是有效的,'@ {n + 1}'不是。 –

+0

對不起@七相最大。在看到您的評論之前發佈答案。認爲你應該發佈你的評論也作爲答案。 – Harry

回答

3

的錯誤是由於以下行:

.testi-square:nth-of-type(@{n + 1}) {order: (@i + 1);} 
.testi-square:nth-of-type(@{n + 2}) {order: (@i + 2);} 

當編譯器遇到的@{n + 1},它會尋找一個名爲n + 1變量。您沒有任何名爲n + 1的變量(並且它也不是有效的語法)。所以,這會導致編譯錯誤。此修復程序會使用這樣的:

@loop-start: 1; 
@loop-end: 20; 
.loop(@n, @i) when (@n =< @loop-end) { 
    .testi-square:nth-of-type(@{n}) {order: (@i);} 
    @temp: @n + 1; 
    .testi-square:nth-of-type(@{temp}) {order: (@i + 1);} 
    @temp2: @n + 2; 
    .testi-square:nth-of-type(@{temp2}) {order: (@i + 2);} 

    .loop((@n + 3), (@i + 6)); // next iteration 
} 
.loop(@loop-start, @loop-start); // launch the loop 

正如在他的評論中指出的七個階段-MAX,我們不能使用表達式,函數調用等選擇插值內。只允許變量。

+1

啊工作!謝謝,有用的解釋 –

+0

不客氣@AlexPaxton。樂於幫助 :) – Harry