【问题标题】:Make ExtJS center item of border layout scroll horizontally使边框布局的ExtJS中心项水平滚动
【发布时间】:2012-04-06 03:05:26
【问题描述】:

我有一个带有边框布局的容器的 ExtJS 视口,我希望中心区域中的容器支持水平滚动。这就是代码现在的样子(这是 Rails 应用程序的一部分,所以请原谅渲染部分内容的 ERB 代码):

    var viewport = Ext.create('Ext.container.Viewport', {
      defaultType: 'container',
      layout: 'border',
      items: [
        {
          defaultType: 'container',
          minWidth: 800,
          region: 'north',
          items: [
            <%= render "shared/header" %>
            ,<%= render "shared/title_bar" %>
          ]
        },{
          defaultType: 'container',
          minWidth: 800,
          region: 'center',
          autoScroll: true,
          items: [
            <%= ext_site_flash_panel(:alert, flash[:site_alert]) %>,
            <%= ext_site_flash_panel(:notice, flash[:site_notice]) %>,
            <%= ext_flash_panel(:alert, flash[:alert]) %>,
            <%= ext_flash_panel(:notice, flash[:notice]) %>,
            {
              defaultType: 'container',
              margin: '20 20 20 20',
              defaults: {
                margin: '0 0 15 0'
              },
              items: [
                <% if content_for?(:top_section) %>
                  <%= yield :top_section %>,
                <% end %>
                <%= content_for?(:main_content) ? yield(:main_content) : yield %>
              ]
            },{
              id: 'footer',
              defaultType: 'container',
              padding: '10 0 10 0',
              layout: {
                type: 'hbox',
                align: 'middle',
                pack: 'center'
              },
              items: [
                {
                  html: '<%= escape_javascript(render 'shared/copyright') %>'
                }
              ]
            }
          ]
        }
      ]
    }); 

我期望的行为是,当窗口的大小使中心容器的宽度小于 800 像素时,它将变为可滚动的。相反,它只是从屏幕的一侧滑落而不允许我滚动到它,尽管它仍然呈现为好像窗口有 800 像素以适应内容。将autoScroll 设置为 true 似乎只是为了确保当内容对于窗口来说太大时我们可以垂直滚动。

如何获得所需的行为?

注意:尝试了this very similar question 中提到的解决方案,但似乎不起作用。

【问题讨论】:

  • 您是否尝试在中心面板上设置宽度属性?

标签: javascript extjs extjs4 horizontal-scrolling border-layout


【解决方案1】:

我的做法与Krzysztof 的解决方案略有不同。

在 Ext JS v6+ 中,scrollable: true 需要在中心区域内的面板上指定。

{
    xtype: 'panel',
    layout: 'border',
    items: [{
        xtype: 'toolbar',
        region: 'north',
        items: ['->', {
            xtype: 'button',
            text: 'Update'
        }]
    }, {
        defaultType: 'container',
        layout: 'fit',
        region: 'center',
        items: [{
            xtype: 'panel',
            scrollable: true, // scrollable center panel
            items: [ /* center panel content */ ]
        }]
    }]
}

【讨论】:

    【解决方案2】:

    一种解决方案是用合适的布局将中心区域包裹在另一个容器中,并在这个新容器上设置autoScroll

    {
        defaultType: 'container',
        layout: 'fit',
        region: 'center',
        autoScroll: true, // WARNING: deprecated since v5.1.0 (use scrollable)
        scrollable: true, // v5.1.0+
        items: [ /* your current center panel goes here */ ]
    }
    

    工作样本:http://jsfiddle.net/H4vp7/

    【讨论】:

    • 谢谢!完美地工作。这是我为数不多的几件没有尝试过的事情之一。
    • autoScroll: true 自 5.1.0 版起已弃用,请改用 scrollable: true
    猜你喜欢
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多