Rendering ExtJS 4+ MVC application in a html div - how-to?

后端 未结 4 1488
时光取名叫无心
时光取名叫无心 2021-02-04 18:03

All examples that I have found so far explain how to render ExtJS (4.2) MVC application within the \"viewport\", which in other words means full browser screen, and occupying wh

相关标签:
4条回答
  • 2021-02-04 18:33

    I liked Evan Trimboli's concise approach but I could not get it to work either (it also told me that MyContainer is not defined). However this approach worked...

    launch: function () {    
        Ext.create('widget.MyContainer', {
            renderTo: 'MyDiv'
        });
    }
    

    ...where 'widget.MyContainer' is the alias created inside the view itself, and provided I also did this up top:

    Ext.define('MyApp.Application', {
        extend: 'Ext.app.Application',
    
        name: 'MyApp',
    
        views: [
            'MyApp.view.MyContainer'
        ],
    ...
    
    0 讨论(0)
  • 2021-02-04 18:45

    Have you tried using Ext.panel.Panel or Ext.window.Window as a container?

    <div id="appBox">
    <script type="text/javascript">  
    
    Ext.require('Ext.panel.Panel');
            Ext.onReady(function(){
    
                Ext.create('Ext.panel.Panel', {
                    renderTo: Ext.getBody(),
                    width: 400,
                    height: 300,
                    title: 'Container Panel',
                    items: [
                        {
                            xtype: 'panel',
                            title: 'Child Panel 1',
                            height: 100,
                            width: '75%'
                        },
                        {
                            xtype: 'panel',
                            title: 'Child Panel 2',
                            height: 100,
                            width: '75%'
                        }
                    ]
                });
    
    
            })
    
        </script>
    </div>
    
    0 讨论(0)
  • 2021-02-04 18:52

    In some of these answers, some suggest using an Ext.Panel with a renderTo. You shouldn't be using an Ext.Panel if you're not going to be utilizing it for anything other than a container if you're going to go this route. You should be using Ext.container.Container instead.

    By using Ext.Panel you are adding a bunch of unnecessary things like the title bar and such to your component. Each one of these puts extra place holders there even if you aren't using them.

    0 讨论(0)
  • 2021-02-04 18:53

    A viewport is just a specialized Ext.container.Container that auto sizes to the the document body.

    As such, you can easily create your own in the launch method:

    launch: function(){
        new MyContainer({
            renderTo: 'myDiv'
        });
    }
    
    0 讨论(0)
提交回复
热议问题