SmartAdmin HTML 版本导航错误 - 在多级导航上加倍锚点
SmartAdmin HTML Version Nav Bug - Doubling up Anchor on Multiple Level Navigation
我认为这是 HTML 我从 asp.net 生成并通过后面的 C# 代码生成的问题。本质上,我正在使用 ListView 生成 SmartAdmin 导航,该 ListView 的代码隐藏函数绑定到它的 OnItemDataBound 函数。
<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>
有没有人运行遇到过类似的问题?
后来我发现这是我使用 ASP:Repeater 生成 HTML 的错误。 Smart admin JS 没想到会在页面加载时以这种格式生成它,因此它坏了。
我认为这是 HTML 我从 asp.net 生成并通过后面的 C# 代码生成的问题。本质上,我正在使用 ListView 生成 SmartAdmin 导航,该 ListView 的代码隐藏函数绑定到它的 OnItemDataBound 函数。
<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>
有没有人运行遇到过类似的问题?
后来我发现这是我使用 ASP:Repeater 生成 HTML 的错误。 Smart admin JS 没想到会在页面加载时以这种格式生成它,因此它坏了。