2017-07-28 77 views
1

我有一個jsp頁面與JSTL tags.jsp頁面包含2個不同tab.If用戶單擊第一個選項卡,然後要顯示與tbody包含值列表的表。罰款。現在我想改變c:forEach項目,當用戶點擊第二個選項卡。兩個選項卡列表包含相同的參數與不同的值。所以我需要改變c:forEach項目使用javascript。這可能嗎 ?更改c:forEach列表項目使用javascript

感謝你

在JSP中

<table id="dynamic-table"> 
<thead> 
<tr> 
<th>Sl.No.</th> 
<th class="sorting_disabled">Loan Id</th> 
<th class="sorting_disabled">Name</th> 
</tr> 
</thead> 
<tbody> 
<c:forEach var="mainlist" items="${S1List}" varStatus="status"> 
<tr> 
<td class="center">${status.index + 1}</td> 
<td>${mainlist.loanId}</td> 
<td>${mainlist.name}</td> 
</tr> 
</tbody> 
</table> 

我想= 「$ {S2List}」 使用JavaScript

的Javascript

更改的項目= 「$ {S1List}」 項
funcion changevalueWhenSecondTabclick(){ 
//I want the solution code here 
} 

回答

1

你可以使用Jquery實現這個功能。您應該將S2List存儲在jQuery變量中。在我看來,我如下

$(document).ready(function() { 
    //This part let's you to store the list in Java script variable 
    var list2ObjectValue="${S2List}"; 

    funcion changevalueWhenSecondTabclick(){ 
    //I want the solution code here 
    $('#dynamic-table tbody').empty(); 
    $.each(list2ObjectValue, function(index, value){ 
     $('#dynamic-table').append('<tr>' 
       +'<td class="center">' + index + '</td>' 
       +'<td>' + value.loanId + '</td>' 
       +'<td>' + value.name + '</td>' 
       +'</tr>'); 
    }); 
    } 
}); 

嘗試以同樣的方式被點擊第一個選項卡時,將實現這一目標。