2016-09-30 33 views
0

我想要迭代一個基於整數值的循環,如果整數值是5,那麼循環將迭代五次,如如何在視覺上使用整數值迭代循環多少次的值?

我知道一種方法來做到這一點使用JSTL在JSP頁面:

<c:forEach var="item" begin="1" end="${properties.value}" varStatus="loop"> 
    //statement 
</c:forEach> 

以上「結尾」,從對話框即時得到的值,如果我傳遞像5的值,那麼循環將得到執行5次。

我提到以下鏈接:

我做了幾個谷歌搜索,以及和我不覺得這種情況下的任何實例,每個實例是基於悅目名單。

我想這樣做基於從對話框傳遞的整數值視力。

感謝,

Arpit寶來

回答

1

分享我的解決方案,這將可幫助他人:)...

經過谷歌搜索,並從Sightly/HTL Documentation我才知道,通過收集悅目/ HTL迭代只

所以我用「HTL JavaScript Use-API」來實現我的問題解決方案。

首先在我的.js文件中,得到對話框的整數值後,我返回一個基於該值的數組。 以下是我的「itemCount.js」文件的代碼:使用即時遍歷數組悅目列表(數據狡猾列表)

"use strict"; 
use(function() { 
    var count = properties["loopCountValue"]; 

    return new Array(Number(count)); 
}); 

其次在我的.html文件。 以下是我的 「testCount.html」 文件的代碼:

<sly data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}" /> 
<sly data-sly-use.itemCount="itemCount.js" data-sly-unwrap /> 

<sly data-sly-test="${!itemCount}"> 
    <div> 
     <h2>Iterate a sightly loop based on Integer value passed from dialog.</h2> 
    </div> 
</sly> 

<sly data-sly-test="${itemCount}"> 
    <p>Test Count ${itemCount}</p> 

    <ul data-sly-list.contentCount="${colCount}"> 
     <li>ITEMS : ${contentCountList.count}</li> 
    </ul> 
</sly> 

-

感謝,

Arpit寶來