2009-06-06 86 views
0

我正在使用MVC與C#也與jQuery。在Jquery中設置活動手風琴

我正在使用jquery手風琴查看員工詳細信息列表。 點擊手風琴時,它會顯示員工的詳細信息。

當我點擊員工編輯時,它會進入員工詳細信息頁面,保存後會在會話中擁有EmployeeDetailsID。當我回到手風琴頁面時,帶有最後更新員工的手風琴應該默認打開(即Accordion應該基於會話中的EmployeeDetailsID打開)。

請建議如何做到這一點。

以下是供參考的代碼。

<html> 
<body> 
<div class="accordion" id="accordion"> 
    <%if (Model != null && Model.EmployeeList != null && Model.EmployeeList.Count > 0) 
       { 
        foreach (EmployeeDetails _employee in Model.EmployeeList) 
        { 
    %> 
    <h3> 
     <div class="heading_acc"> 
      <a href="#" onclick="javascript:ShowEmployees(<%= _employee.EmployeeDetailsID %>);" 
       id="aEmployee"><b><span class="dash_title_bar_right"> 
        <%=Html.Encode(_employee.EmployeeName)%></b> </a> 
     </div> 
    </h3> 
    <div> 
     <div id="divReturns<%= _employee.EmployeeDetailsID %>"> 
      <table width="100%" class="list_contentregion"> 
       <tr> 

        <th class="dash_table_head"> 
         Name 
        </th> 
        <th class="dash_table_head"> 
         Role 
        </th> 
        <th class="dash_table_head"> 
         Branch 
        </th> 
        <th class="dash_table_head"> 
         Last Updated 
        </th> 
       </tr> 
       <tr id="trEmp<%= _employee.EmployeeDetailsID %>" class="dash_label"> 

        <td> 
         <div id="lblName<%= _employee.EmployeeDetailsID %>"> 
         </div> 
        </td> 
        <td> 
         <div id="lblRole<%= _employee.EmployeeDetailsID %>"> 
         </div> 
        </td> 
        <td> 
         <div id="lblBranch<%= _employee.EmployeeDetailsID %>"> 
         </div> 
        </td> 
        <td> 
         <div id="lblTime<%= _employee.EmployeeDetailsID %>"> 
         </div> 
        </td> 
       </tr> 
      </table> 
     </div> 
    </div> 
    <%} 
       } %> 
</div> 

</body> 
</html> 

回答

1

當你編輯員工數據我希望你在你的員工列表所述用戶返回到正確的頁面。

就當你是通過你的員工列表循環,你可以對會話變量檢查_employee.EmployeeDetailsID值,然後編寫循環itteration數出一個<腳本>塊調用以下代碼假設。

$("#accordion").accordion('activate' , loopIndex); 

jQuery的手風琴的文檔可以在這裏找到,以及這種方法http://docs.jquery.com/UI/Accordion#method-activate

請從文檔注意我看過其他的細節,我不認爲你應該使用會話變量對於這種的東西。

我會推薦通過MVC路由系統返回變量作爲路由值。以下面的代碼爲例。

new { Controller = "Employee", Action = "List", Page = pageNumber, EmployeeId = EmployeeDetailsID } 
+0

'method'ahem只適用於jqueryUI 1.8。之後,你必須使用'jquery(「。selector」)。accordion(「option」,{active:index}) – 2015-11-03 22:31:00