0

I am a new one to ExtJs 6.0 and I have to make a web page that will be automatically filled with HTML text. On the localhost it works fine but when I try to load my app through index.html that is in my App folder it displays nothing

This is my first class "List"

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
    { name:'position', type:'string' },
    { name:'title', type:'string' },
        {name:'rate', type:'string'}
    ]
    });
    var store = Ext.create('Ext.data.Store', {
        model: 'User',
        proxy: {
             type: 'ajax',
             url: '/app/view/main/data.json',
            method:'GET',
            reader: {
                 type: 'json',
                 root: 'foo'
             }
         },
         autoLoad: true
      });
     var notiTpl = new Ext.XTemplate(
     '<h1>TIOBE rate</h1>',
                                        '<table>',
                                            '<tr>',
                                                '<td>Position on 2015</td>',
                                                '<td>Programming language</td>',
                                                '<td>Rate</td>',
                                                '<td>Group</td>',
                                            '</tr>',
                                            '<tpl for=".">',
                                            '<tr <tpl if="values.position%2 ==         1">style="background-color: silver;"</tpl>>',
                                                '<td>{position}</td>',
                                                '<td>{title}</td>',
                                                '<td>{rate}</td>',
                                                '<tpl if="values.position<3">',
                                                    '<td>A</td>',
                                                '<tpl elseif="values.position<5">',
                                                        '<td>B</td>',
                                                '<tpl else>',
                                                        '<td>C</td>',
                                                '</tpl>',
                                            '</tr>',
                                            '</tpl>',
                                        '</table>');

 Ext.define('App.view.main.List', {
    extend: 'Ext.view.View',
    xtype: 'mainlist',
    store: store,
      tpl: notiTpl,
      itemSelector: 'div.thumb-wrap',
      emptyText: 'There is no text',
      renderTo: Ext.getBody()

});

Second class "Main"

Ext.define('App.view.main.Main', {
    extend: 'Ext.panel.Panel',

    requires: [
        'Ext.plugin.Viewport',
        'Ext.window.MessageBox',

        'App.view.main.List'
    ],


    items: [{
        title: 'Some html text',
        items: [{
            xtype: 'mainlist'
        }]
    }]
});

My 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 upgrading.
 */
Ext.application({
    name: 'App',

    extend: 'App.Application',

    requires: [
        'App.view.main.Main'
    ],

    // The name of the initial view to create. With the classic toolkit this class
    // will gain a "viewport" plugin if it does not extend Ext.Viewport. With the
    // modern toolkit, the main view will be added to the Viewport.
    //
    mainView: 'App.view.main.Main'

    //-------------------------------------------------------------------------
    // Most customizations should be made to App2.Application. If you need to
    // customize this file, doing so below this section reduces the likelihood
    // of merge conflicts when upgrading to new versions of Sencha Cmd.
    //-------------------------------------------------------------------------
});

My Application.js

/**
 * The main application class. An instance of this class is created by app.js when it
 * calls Ext.application(). This is the ideal place to handle application launch and
 * initialization details.
 */
Ext.define('App.Application', {
    extend: 'Ext.app.Application',

    name: 'App',

    stores: [
        // TODO: add global / shared stores here
    ],

    launch: function () {
      Ext.create('App.view.main.Main').show();
    },

    onAppUpdate: function () {
        Ext.Msg.confirm('Application Update', 'This application has an update, reload?',
            function (choice) {
                if (choice === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});

My index.html

    <!DOCTYPE HTML>
<html manifest="">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <title>App</title>
  <script type="text/javascript" src="ext/build/ext-all.js"></script>

        <script type="text/javascript" src="app.js"></script>



    <!-- The line below must be kept intact for Sencha Cmd to build your application -->
    <script id="microloader" data-app="b0beccc4-d014-4af3-919d-fd0a75c6c656" type="text/javascript" src="bootstrap.js"></script>

</head>
<body></body>
</html>

I've already read tons of documentation but nothing helps.

UPDATE

I don't know how but now it displays only the part of xtemplate loop. It stucks on the part where it begins rendering through data from json, though localhost:1841 still displays the whole info

  • Ye it's a [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) issue - it needs to be viewed behind a server or virtual host (or localhost). Some browsers such as Chrome allow you to disable the [same origin policy](http://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome) for debugging purposes - but if you already have the means to setup a local server, why do you need to load it directly from the file system? – Emissary Mar 23 '16 at 19:17
  • I have a task to display through the index. – Artem Yudenko Mar 23 '16 at 22:08
  • @Emissary Thank you very much, you saved my day)) – Artem Yudenko Mar 24 '16 at 05:11

1 Answers1

1

I figgured this out. The point was about CORS. If someone has the same problem - just use Mozila.

  • Or you can quickly launch lightweight webserver from your app location, just write in console: `sencha web --port 8080 start` – pagep Mar 24 '16 at 10:08