将多个参数传递给thymeleaf标记的javascript函数

Aru*_*amy 4 html javascript jquery thymeleaf

我对百日咳很新.在这里,我一直坚持传递参数.这是我的html页面.

<tr th:each="result : ${searchResult}">
<td>
    <a href="#" th:text="${result.getString('type')} +'|'+  ${result.getString('name')} +'|'+  ${result.getString('revision')}"></a>
</td>
<td>
    <a href="#" role="button" class="green" data-toggle="" onclick="dataSearchAjax1('Source','sourceResultDiv')">view</a>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

这是我的javascript函数

function dataSearchAjax1(searchType, resultDiv) {
        var typeVar=searchType;
        $.ajax({
            url : 'dataSearchAjax1',
            data: {type:typeVar},
            success : function(data) {
                $('#'+resultDiv).html(data);
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

这里我必须传递result.getString('type')和result.getString('name')而不是'source'和'sourceResultdiv'.

我试过了

 th:onclick="'javascript:dataSearchAjax1(\'' + ${result.getString('type')},${result.getString('name')} + '\');'"
Run Code Online (Sandbox Code Playgroud)

我也尝试过:attr ="online ... tag ..两个都没有用.有人可以帮帮我吗?

Lea*_*edo 8

您还需要转义,分隔符,因此执行函数调用的代码将是:

th:onclick="'javascript:dataSearchAjax1(\'' + ${result.getString('type')} +'\',\''+ ${result.getString('name')} + '\');'"
Run Code Online (Sandbox Code Playgroud)