将arrayList索引发送到Thymeleaf中的ajax函数

时间:2014-06-05 19:48:14

标签: javascript thymeleaf

我的Jsp页面中有以下列表。列表中的每一行都有一个按钮。 当我点击那个按钮时,我需要将行索引传递给控制器​​。

<tr th:each="idBean : ${idBeanLst}" >
                <td th:text="${idBeanStat.count}" id="count"></td>
                <td th:text="${idBean.identifierId}" id="idenId"></td>
                <td th:text="${idBean.idNumber}" id="idNumber"></td>
                <td th:text="${idBean.issueLocation}" id="issueLocation"></td>
                <td th:text="${idBean.issueDate}" id="issueDate"></td>
                <td th:text="${idBean.expiryDate}" id="expDt"></td>

                <td><button type="button" name="identifierRow" id="identifierRow" th:value="${idBeanStat.index}" onclick="doAjaxCallRemoveIdentifier(${idBean.index})">Remove</button>
                </td>

function doAjaxCallRemoveIdentifier(id) {
        alert(id);
            //do ajax call to the controller..
}

但是我无法传递行ID。非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

这对我有用

<button type="button" name="identifierRow" id="identifierRow" th:value="${idBeanStat.index}" th:onclick="'javascript:doAjaxCallRemoveIdentifier(\'' + ${idBeanStat.index} + '\');'">Remove</button>

感谢@ohiocowboy建议我使用th:onclick.Hope这有助于其他人。

答案 1 :(得分:0)

参见文档6.2。 http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html

${idBean.index}会为您提供索引

相关问题