2017-03-01 18 views
0

SpringからThymeleaf ArrayListに送信します。これは2つのBigDemicalパラメータから構成されています。この価格フィルタのため、私がやりたい:0からのArrayListから最初の要素を、最初の要素から2番目と複数の第二の 春に:SpringからThymeleafへの選択値を受け入れる方法

modelAndView.addObject("price",filterPrice); 

Htmlの

<div th:each="filterPrice : ${price}"> 
        <input class="priceSelected" type="checkbox" id="price01" value="1"/> 0 - 
        <span class="filterPriceFirst" th:text="${price[0]}"></span> <br/> 

<input class="priceSelected" type="checkbox" id="price02" value="2"/> 
<span class="filterPriceFirst" th:text="${price[0]}"> 
-<span class="filterPriceFirst" th:text="${price[1]}"></span> <br/> 

<input class="priceSelected" type="checkbox" id="price02" value="3"/> 
> <span class="filterPriceFirst" th:text="${price[1]}"> 
<br/> 
        </div> 

作業コードが、私はreciveすべての値は2回です。しかし、私はすべての価値を1回だけ受けなければなりません。私の誤った発言はどこですか?

答えて

0

HTMLでは、配列をループする各要素が使用されています。配列には2つの要素があるので、2回実行します。 thを削除:それぞれ修正します。また、最後の入力時にprice03を使用する必要があるため、要素IDは一意でなければなりません。

あなたのコードは、この

<div> 
    <input class="priceSelected" type="checkbox" id="price01" value="1"/> 0 - 
    <span class="filterPriceFirst" th:text="${price[0]}"></span> 
    <br/> 

    <input class="priceSelected" type="checkbox" id="price02" value="2"/> 
    <span class="filterPriceFirst" th:text="${price[0]}">- 
    <span class="filterPriceFirst" th:text="${price[1]}"></span> 
    <br/> 

    <input class="priceSelected" type="checkbox" id="price03" value="3"/> > 
    <span class="filterPriceFirst" th:text="${price[1]}"> 
    <br/> 
</div> 
のようになります
関連する問題