在百里香中添加带有th:each的动态属性

时间:2018-07-30 23:36:18

标签: jquery ajax spring-boot thymeleaf

我想定义一个动态属性,该属性可以使用所选选项动态更改。

* HTML /胸腺代码*

<tr th:field="*{listArticles}">
  <td>
    <select class="custom-select" id="libelleArticle" name="libelleArticle">
      <option value=""> Selectionner un article </option>
      <option th:each="article : ${listArticles}" id="selectArt" 
              th:value="${article.libelleArticle}"
              th:text="${article.libelleArticle}"
              th:attr="att=${article.prixHT}" />                        
      </select>
  </td>

  <td>
    <input type="text" class="form-control" id="prix" name="prix" 
            th:value="${priceArt}" th:text="${priceArt}" /> 
  </td>
</tr>

* jQuery代码*

$("table #libelleArticle").change(function() { 
  var price = $("#selectArt").attr('att');
  $("#prix").val(price);
});

* Spring Boot控制器代码*

@RequestMapping(value="/newCommande", method=RequestMethod.GET)
public String home(Model model) {
  List<Article> listArticles = articleRepository.findAll();
  model.addAttribute("listArticles", listArticles);
  return "newCommande";
}

0 个答案:

没有答案