2015-04-20 56 views
0

我有一個帶有多個子菜單的Devexpress MenuBar控件。我想在哪裏使用Javascript動態更改菜單欄方向。我試圖至今:更改方向Devexpress使用javascript調整窗口大小的MenuBar控件

<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 

能否請您在此幫助得到了一個錯誤。

回答

1

我從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; 
    }