2016-08-25 65 views
0

我認爲這是一個HTML問題,我通過asp.net和通過後面的C#代碼生成。從本質上講,我使用ListView生成SmartAdmin導航,其中有一個函數綁定到它的OnItemDataBound函數後面的代碼。SmartAdmin HTML版導航錯誤 - 在多級導航上加倍錨點

<asp:ListView OnItemDataBound="lvwMenu_ItemDataBound" ID="lvwMenu" runat="server" > 
       <LayoutTemplate> 
        <nav> 
         <!-- 
         NOTE: Notice the gaps after each icon usage <i></i>.. 
         Please note that these links work a bit different than 
         traditional href="" links. See documentation for details. 
         --> 
         <ul> 
          <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> 
         </ul> 
        </nav> 
       </LayoutTemplate> 
       <ItemTemplate> 
        <li class="<%# If(Container.DataItemIndex.Equals(0), "active", "")%>"> 
         <asp:PlaceHolder ID="pnlAnchorAll" runat="server"> 
          <a id="lkbtnData" runat="server" title='<%# Bind("Description")%>'> 
           <i class="fa fa-lg fa-fw <%# DataBinder.Eval(Container.DataItem, "Label") %>"></i> <span class="menu-item-parent"><%# DataBinder.Eval(Container.DataItem, "Description")%></span> 
           <%--  Repeater is here generating second level of pages --%> 
          </a> 
         </asp:PlaceHolder> 
        </li> 
       </ItemTemplate> 
      </asp:ListView> 

這裏是DataBound事件代碼功能的背後:

Protected Sub lvwMenu_ItemDataBound(sender As Object, e As ListViewItemEventArgs) 
    If e.Item.ItemType = ListViewItemType.DataItem Then 
     Dim rowView As DataRowView 
     rowView = DirectCast(e.Item.DataItem, DataRowView) 

     Dim lkbtnData As HtmlAnchor, pnlAnchorAll As PlaceHolder, rptSubMenu As Repeater 

     If rowView("Description").ToString().Equals("Second Level", StringComparison.OrdinalIgnoreCase) Then 
      rptSubMenu = DirectCast(e.Item.FindControl("rptSubMenu"), Repeater) 
      oBSAOM = New MD.bsAOM(_oSession:=Session) 
      oBSAOM.bGetSecondLevel("Pages", rptSubMenu) 
      lkbtnData.HRef = "javascript:void(0)" 
     Else 
      lkbtnData.HRef = rowView("Value").ToString() 
     End If 

    End If 
End Sub 

我使用一箇中繼器生成的

<asp:Repeater ID="rptSubMenu" runat="server"> 
            <HeaderTemplate> 
             <ul class=""> 
            </HeaderTemplate> 
            <ItemTemplate> 
             <li> 
              <a id="lkbtnSubData" runat="server" title='<%# Bind("Description")%>' href='<%# Bind("Value")%>'> 
               <i class="fa fa-fw fa-folder-open"></i> <%# DataBinder.Eval(Container.DataItem, "Description")%> 
              </a> 
             </li> 
            </ItemTemplate> 
            <FooterTemplate> 
             </ul> 
            </FooterTemplate> 
           </asp:Repeater> 

而生成的源頁面的第二級時輸出到瀏覽器是:

  <nav> 
         <!-- 
         NOTE: Notice the gaps after each icon usage <i></i>.. 
         Please note that these links work a bit different than 
         traditional href="" links. See documentation for details. 
         --> 
       <ul> 

        <li class="active"> 
         <a href="Home.aspx" id="ctl00_lvwMenu_ctrl0_lkbtnData" title="Home"> 
           <i class="fa fa-lg fa-fw fa-home"></i> <span class="menu-item-parent">Home</span> 

          </a> 


        </li> 
        <li class=""> 
         <a href="javascript:void(0)" id="ctl00_lvwMenu_ctrl5_lkbtnData" title="Second Level"> 
           <i class="fa fa-lg fa-fw fa-dollar"></i> <span class="menu-item-parent">Second Level</span> 
           <!-- BEGIN Second Level Example here --> 
            <ul> 

             <li> 
              <a href="../SecondLevel/Page.aspx" id="ctl00_lvwMenu_ctrl5_rptSubMenu_ctl01_lkbtnData" title="2nd Level Page"> 
               <i class="fa fa-fw fa-folder-open"></i> 2nd Level Page 
              </a> 
             </li> 

            </ul> 
           <!-- END Second Level Example here -->  
         </a> 


        </li> 

       </ul> 
      </nav> 

看起來正確。但什麼是在頁面加載立即發生在源被修改(我相信通過SmartAdmin的JS)到:

<li> 
       <a title="Second Level" id="ctl00_lvwMenu_ctrl5_lkbtnData" href="javascript:void(0)"> 
        <i class="fa fa-lg fa-fw fa-dollar"></i> <span class="menu-item-parent">Second Level</span> 
        <b class="collapse-sign"><em class="fa fa-plus-square-o"></em></b> 
       </a> 
       <!-- BEGIN Second Level Example here --> 
       <ul style="display: none;"> 
        <a title="Second Level" id="ctl00_lvwMenu_ctrl5_lkbtnData" href="javascript:void(0)"> <!-- Anchor Tag is incorrectly generated here --> 
        </a> 
        <li> 
         <a title="Second Level" id="ctl00_lvwMenu_ctrl5_lkbtnData" href="javascript:void(0)"> <!-- Anchor Tag is incorrectly generated here --> 
         <a title="Page" id="ctl00_lvwMenu_ctrl5_rptSubMenu_ctl01_lkbtnSubData" href="../SecondLevel/Page.aspx"> 
          <i class="fa fa-fw fa-folder-open"></i> Page 
         </a> 
        </li> 
       </ul> 
       <!-- END Second Level Example here -->     
     </li> 

任何人以任何機會之前遇到類似的問題?

回答

0

我後來發現我在使用ASP:Repeater生成HTML的過程中遇到了一個錯誤。智能管理JS並沒有期望在頁面加載時以該格式生成它,因此它打破了。