ExtJS 4+ MVC application rendering in html div - how?

All the examples that I have found so far explain how to render the MVC ExtJS (4.2) application in the "viewport", which means that it is a full browser screen and takes up all the HTML code.

I would like to display the application on an existing HTML page in the DIV title so that I can have HTML design around the application.

<div id="appdiv"><!-- application runs here --></div> 

I saw some sites with ExtJS 4 examples that use a trick to render an ExtJS application on a page using IFRAME.

Is it possible to avoid an iframe? And if so, what does the skeleton of the ExtJS 4.2 application look like if it is displayed in a div.

Notes. In ExtJS 3, I found a solution by creating a panel as the main container that displays inside the named div. However, version 4.2 (and possibly earlier versions 4.x) offers an approach to MVC applications that seems far superior.

---- Editing

I realized that I had to put the starting points for this question.

  • The source for this example is generated by the ExtJS CMD command, which generates the application wireframe.
  • The application’s skeleton consists of many files, including a link to the engine, and other links, so I couldn’t include all the sources in the "application" dir / folder here. The application’s skeleton can be made using cmd into fashion: sencha -sdk /myuserroot/Sencha/Cmd/3.1.1.274 generate app ExtGenApp /mywebroot/htdocs/extja_genapp This creates files and folders and copies all the necessary files into place.
  • The scope of the "User" is in the "app" directory. The dir app has tricks for browsing, controllers, models, and additional content.
  • As in many other environments, you must maintain the folder structure so that the environment can find the appropriate files and initialize them.
  • list of files:

index.html (at the root of the created application)

  <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>ExtGenApp</title> <!-- <x-compile> --> <!-- <x-bootstrap> --> <link rel="stylesheet" href="bootstrap.css"> <script src="ext/ext-dev.js"></script> <script src="bootstrap.js"></script> <!-- </x-bootstrap> --> <script src="app/app.js"></script> <!-- </x-compile> --> </head> <body> <h1>HTML Before</h1> <div id="appBox"></div> <h1>HTML After</h1> </body> </html> 

app / app.js

  /* This file is generated and updated by Sencha Cmd. You can edit this file as needed for your application, but these edits will have to be merged by Sencha Cmd when it performs code generation tasks such as generating new models, controllers or views and when running "sencha app upgrade". Ideally changes to this file would be limited and most work would be done in other places (such as Controllers). If Sencha Cmd cannot merge your changes and its generated code, it will produce a "merge conflict" that you will need to resolve manually. */ // DO NOT DELETE - this directive is required for Sencha Cmd packages to work. //@require @packageOverrides Ext.application({ name: 'ExtGenApp', views: [ 'Main', 'appBoxView' ], controllers: [ 'Main' ], launch: function() { new Ext.view.appBoxView({ renderTo: 'appBox' });; // generates error } }); 

Note: initially there is no launch function, but there is an automatic creation of the viewport (it turns out that by default the generator)

Application / Controller / Main.js

  Ext.define('ExtGenApp.controller.Main', { extend: 'Ext.app.Controller' }); 

app / view / appBoxView.js

  Ext.define('ExtGenApp.view.appBoxView', { extend: 'Ext.panel.Panel', requires:[ 'Ext.tab.Panel', 'Ext.layout.container.Border' ], layout: { type: 'border' }, items: [{ region: 'west', xtype: 'panel', title: 'west', width: 150 },{ region: 'center', xtype: 'tabpanel', items:[{ title: 'Center Tab 1' }] }] }); 

it should be the initial layout on the screen (AFAIK)

and finally:

app / view / Main.js

  Ext.define("ExtGenApp.view.Main", { extend: 'Ext.Component', html: 'Hello, World!!' }); 

which, as I understand it, should be "content."

as it is, it generates an error without creating "Ext.view.appBoxView" and as it looks to me, the framework does not initialize the application.

+6
source share
5 answers

The Ext.container.Container is just the specialized Ext.container.Container , which is automatically configured for the body of the document.

This way you can easily create your own startup method:

 launch: function(){ new MyContainer({ renderTo: 'myDiv' }); } 
+3
source

You need to use a different container than Ext.container.Viewport . By definition, Ext.container.Viewport will always occupy the entire browser window.

From the documentation:

 The Viewport renders itself to the document body, and automatically sizes itself to the size of the browser viewport and manages window resizing. There may only be one Viewport created in a page. 

Just use Ext.panel.Panel instead

See sample below.

 Ext.application({ name: 'HelloExt', launch: function() { Ext.create('Ext.panel.Panel', { layout: 'fit', renderTo: Ext.get('content') items: [ { title: 'Hello Ext', html : 'Hello! Welcome to Ext JS.' } ] }); } }); 

also see link below

http://www.sencha.com/forum/showthread.php?141964-Render-an-ExtJs-4-application-in-a-div http://css.dzone.com/articles/height-problem-when -rendering

+1
source

In some of these answers, some suggest using Ext.Panel with renderTo. You should not use Ext.Panel unless you intend to use it for anything other than a container, if you intend to go this route. Instead, you should use Ext.container.Container.

Using Ext.Panel, you add a bunch of unnecessary things, such as a title bar, etc. to your component. Each of them places additional place holders there, even if you do not use them.

+1
source

I liked Evan Trimboli's concise approach, but I couldn't get it to work (he also told me that MyContainer was not defined). However, this approach worked ...

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

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

 Ext.define('MyApp.Application', { extend: 'Ext.app.Application', name: 'MyApp', views: [ 'MyApp.view.MyContainer' ], ... 
+1
source

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
source

Source: https://habr.com/ru/post/945530/


All Articles