将值传递给for循环</div>中的下一个<div>

时间:2014-05-29 10:56:42

标签: jquery html twitter-bootstrap for-loop

我有一个来自for循环的表,如下所示,

<c:forEach var="teacher" items="${compositeTeacherInfo}">
    <tr>
        <td ><div class="tabcell">${teacher.getTeacherName()}</div></td>
        <td>${teacher.getFormatedDoj()}</td>
        <td>${teacher.getContactNo()}</td>
        <td ><div class="tabcell">${teacher.getEmail()}</div></td>
        <td><a
            href="<%=request.getContextPath()%>/pages/teacher_details/view_teacher_info.jsp?teacherId=${teacher.getTeacherId()}">View</a>
        </td >
        <td><a
            href="<%=request.getContextPath()%>/pages/teacher_details/teacher_info.jsp?teacherId=${teacher.getTeacherId()}">Edit</a>
        </td>
        <td><a href="#" data-toggle="modal" data-target="#basicModal">Delete</a></td>
    </tr>
    <div class="modal fade" id="basicModal" tabindex="-1" role="dialog"
        aria-labelledby="basicModal" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Delete Teacher
                        Record</h4>
                </div>
                <div class="modal-body">

                    <h3>Are you sure?</h3>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                        data-dismiss="modal">No</button>
                    <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
                    <a
                        href="<%=request.getContextPath()%>/controller/TeacherManagementController?flowName=DELETE_TEACHER_INFO&teacherId=${teacher.getTeacherId()}"
                        class="btn btn-primary">Yes</a>
                </div>
            </div>
        </div>
    </div>
</c:forEach>

所以目前我有15行。我在这里要做的是,通过点击delete链接,该行必须被删除。它的工作正常,行将删除,但我一直在努力进行小改动。更改是,在这里我使用Bootstrap,当我点击delete链接时,将打开一个bootstrap模式并要求确认删除。此代码也在for循环中。所以这里当出现模态时它只显示文本Are you sure但是我想要显示名称Are you sure want to delete "Jack" related record。我可以在这里找到的名字来自${teacher.getTeacherName()}。当我将其与模态文本一起添加时,它始终只显示第一个记录的名称。怎么解决这个问题。请帮帮我。

感谢...

1 个答案:

答案 0 :(得分:0)

问题是模态窗口Div ID,它应该是唯一的,即使你尝试在for循环中创建多个模态窗口(DIV)。如果元素ID相同,它就不会创建。

所以,试试吧。它应该工作,如果teacherId是唯一的

<c:forEach var="teacher" items="${compositeTeacherInfo}">
    <tr>
        <td ><div class="tabcell">${teacher.teacherName}</div></td>
        <td>${teacher.formatedDoj}</td>
        <td>${teacher.cotactNo}</td>
        <td ><div class="tabcell">${teacher.email}</div></td>
        <td><a
            href="<%=request.getContextPath()%>/pages/teacher_details/view_teacher_info.jsp?teacherId=${teacher.teacherId}">View</a>
        </td >
        <td><a
            href="<%=request.getContextPath()%>/pages/teacher_details/teacher_info.jsp?teacherId=${teacher.teacherId}">Edit</a>
        </td
        <td><a href="#" data-toggle="modal" data-target="#basicModal_${teacher.teacherId}">Delete</a></td>
    </tr>
    <div class="modal fade" id="basicModal_${teacher.teacherId}" tabindex="-1" role="dialog"
        aria-labelledby="basicModal" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Delete ${teacher.teacherName}
                        Record</h4>
                </div>
                <div class="modal-body">

                    <h3>Are you sure?</h3>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                        data-dismiss="modal">No</button>
                    <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
                    <a
                        href="<%=request.getContextPath()%>/controller/TeacherManagementController?flowName=DELETE_TEACHER_INFO&teacherId=${teacher.teacherId}"
                        class="btn btn-primary">Yes</a>
                </div>
            </div>
        </div>
    </div>
</c:forEach>