在jstl标记中迭代隐藏值

时间:2017-01-08 09:15:35

标签: javascript jsp jstl

我正在使用Ajax调用来设置隐藏值,然后我需要迭代它以形成一个表。

值已设置为隐藏值,但我无法使用jstl标记形成表。

隐藏场:

<input type="hidden" name="hiddenResult" id="hiddenResult" />

表体:

<tbody>
        <c:set var="searchresult" value="${hiddenResult}"></c:set>
        <c:forEach items="${searchresult}" var="searchresult" varStatus="loop">
            <tr>
                <td>${searchresult.schoolName}</td>
                <td>${searchresult.districtName}</td>
                <td>${searchresult.ltiKey}</td>
                <td>${searchresult.ltiSecret}</td>
                <td>
                    <input type="checkbox" name="selectedLtiKeys" id="selectedLtiKeys${loop.index}" style="display: none;" value="${searchresult.ltiKey}"> 
                    <c:if test="${searchresult.status == 'Active'}">
                        <img id="activate${loop.index}" src="../image/activate_button.png"
                                                    onclick="selectedLtiKeys${loop.index}.checked = (!selectedLtiKeys${loop.index}.checked); javascript:toggleImage(${loop.index},false);">
                        <img id="inactivate${loop.index}" style="display: none;" src="../image/inactivate_button.png"
                                                    onclick="selectedLtiKeys${loop.index}.checked = (!selectedLtiKeys${loop.index}.checked); javascript:toggleImage(${loop.index},true);">
                    </c:if> 
                    <c:if test="${searchresult.status == 'InActive'}">
                        <img id="inactivate${loop.index}" src="../image/inactivate_button.png"
                                                        onclick="selectedLtiKeys${loop.index}.checked = (!selectedLtiKeys${loop.index}.checked); javascript:toggleImage(${loop.index},true);">
                        <img id="activate${loop.index}" src="../image/activate_button.png" style="display: none;"
                                                onclick="selectedLtiKeys${loop.index}.checked = (!selectedLtiKeys${loop.index}.checked); javascript:toggleImage(${loop.index},false);">

                    </c:if>
                </td>
            </tr>
        </c:forEach>
</tbody>

1 个答案:

答案 0 :(得分:0)

我不知道任何响应类定义。所以我告诉你关于如何通过ajax调用更新你的表的基本知识。首先加载表数据页面。 假设加载你的表后如:

<table summary="search result" id="data-table" class="search-result" cellspacing="0" style="">
    <thead>
        <tr>
            <th scope="" class="" id="">id</th>
            <th scope="" class="" id="">name</th>
            <th scope="" class="" id="">email</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>some name</td>
            <td>some@some.com</td>
        </tr>
    </tbody>
</table>

现在进行ajax调用并通过下面的代码段更新您的表。

function updateData() {

    var obj = $("#data-table tr");

    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: 'updateData.html',
        data: '', // what you want to sent
        success: function(responseData,textStatus) {
            if (textStatus == 'success' && responseData.length > 0) {
                $('#data-table tbody').html('');

                var row = '';
                for(var i = 0; i< responseData.length;i++){

                var id = responseData[i].id;
                var name = responseData[i].name;
                var email = responseData[i].email;
                // Now prepare the data for the table
                row += '<tr>'+'<td>'+id+'</td>'+'<td>'+name+'</td>'+'<td>'+email+'</td></tr>';

            }
            $('#data-table tbody').html(row);   

            }
        }, error: function(responseData) {
            // show your error message
        }
    });

}

JsFiddle