gpt4 book ai didi

javascript - 使用 javascript 更改窗口调整大小时的方向 Devexpress MenuBar 控件

转载 作者:行者123 更新时间:2023-12-03 10:18:44 25 4
gpt4 key购买 nike

我有一个带有多个子菜单的 Devexpress MenuBar 控件。我想使用 Javascript 动态更改菜单栏方向。到目前为止我尝试的是:

<script type="text/javascript">
window.onresize = function () {
if (window.innerWidth <= 1100) {
RASPxMenuViewSetting.SetOrientation('Vertical');
}
}
</script>

我的菜单代码在哪里:

<dx:ASPxMenu ID="ASPxMenuViewSetting" runat="server" EnableTheming="True" ClientInstanceName="RASPxMenuViewSetting">
<Items>//contains Submenus </Items>
</dx:ASPxMenu>

我在调试时遇到错误

Uncaught TypeError: RASPxMenuViewSetting.SetOrientation is not a function

您能帮忙解决一下吗?

最佳答案

我从 Devexpress 团队得到了如下答案,这对我有用:

Javascript

 <script type="text/javascript">
function OnControlsInitialized(s, e) {
ASPxClientUtils.AttachEventToElement(window, "resize", function (evt) {
if (cp.InCallback())
return;
if (window.innerWidth <= 1100) {
if (RASPxMenuViewSetting.cpOrientation != "Vertical")
cp.PerformCallback("Vertical");
}
else
if (RASPxMenuViewSetting.cpOrientation != "Horizontal")
cp.PerformCallback("Horizontal");
});
}
</script>

ASPX 文件

<dx:ASPxCallbackPanel ID="ASPxCallbackPanel1" runat="server" Width="200px" ClientInstanceName="cp" OnCallback="ASPxCallbackPanel1_Callback">
<PanelCollection>
<dx:PanelContent runat="server">
<dx:ASPxMenu ID="ASPxMenuViewSetting" runat="server" ClientInstanceName="RASPxMenuViewSetting" EnableTheming="True" ItemWrap="false">
<Items>
<dx:MenuItem Text="Item 1">
</dx:MenuItem>
<dx:MenuItem Text="Item 2">
</dx:MenuItem>
<dx:MenuItem Text="Item 3">
</dx:MenuItem>
<dx:MenuItem Text="Item 4">
</dx:MenuItem>
</Items>
</dx:ASPxMenu>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
<dx:ASPxGlobalEvents ID="ASPxGlobalEvents1" runat="server">
<ClientSideEvents ControlsInitialized="OnControlsInitialized" />
</dx:ASPxGlobalEvents>

还需要更改cs文件如下:

protected void ASPxCallbackPanel1_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
{
if (e.Parameter == "Vertical")
ASPxMenuViewSetting.Orientation = Orientation.Vertical;
else
ASPxMenuViewSetting.Orientation = Orientation.Horizontal;

ASPxMenuViewSetting.JSProperties["cpOrientation"] = e.Parameter;
}

关于javascript - 使用 javascript 更改窗口调整大小时的方向 Devexpress MenuBar 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29739793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com