3

我有一个带有边框布局的容器的 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 似乎只是为了确保当内容对于窗口来说太大时我们可以垂直滚动。

如何获得所需的行为?

注意:尝试了在这个非常相似的问题中提到的解决方案,但它似乎不起作用。

4

2 回答 2

6

一种解决方案是将中心区域包装在另一个具有合适布局的容器中,并设置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/

于 2012-03-22T08:57:13.620 回答
0

我不得不与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 */ ]
        }]
    }]
}
于 2019-02-15T13:58:34.440 回答