ExtJS 无法正确显示 Ext.panel.Panel 的 html

ExtJS Can not display Ext.panel.Panel's html properly

我有一个 class 继承自 Ext.grid.Panel 并使用此 class 中的方法显示一个 panel,其中包括两个项目:一个 listtoolbar class 和一名 Ext.XTemplate 员工。

Ext.define('MyApp.view.BGrid', {
    extend: 'MyApp.view.AGrid', //This class extends from 'Ext.grid.Panel'
    requires: [
            ...
            'Ext.layout.container.VBox',
            'MyApp.view.base.ListToolbar'
    ],
    getDashBoardTpl: function () {
        var me = this;

        return [
            {
                xtype: 'panel',
                // html: 'so what?', // Displays the text; See -Img 01
                // html: me.dashTpl(), // Displays as [object object]; See -Img 02
                layout: {type: 'vbox', align: 'stretch', pack: 'center'},
                items:
                    [
                        {
                            xtype: 'listtoolbar', //Display nothing!
                            flex: 1
                        },
                        {
                            xtype: 'panel',
                            name: 'dashtpl',
                            flex: 1,
                            // html: 'so WHat?' //Display nothing!
                            html: me.dashTpl() //Display nothing!
                        }
                    ]
            }
        ]
    },

无法显示面板的项目; listtoolbardashtpl 的 html。而不是当 html 标签使用上面板时它起作用。当第一个面板中使用 dashTpl 函数时,事情就是显示 [Object] [Object]

这里是 dashTpl();

dashTpl: function(){
        var tpl= new Ext.XTemplate(
            '<tpl for=".">' +
                '<div class="dashTpl">'+
                    '<table style="width:100%;height:80px;text-align:center" >'+
                        '<tr style="width:100%;">'+
                            '<td style="box-shadow: 10px 5px 5px #BDBDBD;background-color:#EEEEEE;width:20%">'+
                                '<a>'+
                                    '<span style="font-size:24px;"><b style="color: #8000FF;">5,875.00</b></span><br/>'+
                                    '<div>'+
                                        '<b style="color: #6E6E6E;font-size:14px;">€</b>' +

这可能是什么原因?谢谢指教。

这里是Img 01 and Img 02

@Nuri,在您的代码中设置 html using Ext.XTemplate inside of panel,这不是使用 html 配置的正确方法。

If you want to use html config in panel then you need to set tpl like below example

html:'<table class="x-date-table"><tbody><tr><th>SNo.</th><th>Date</th><th>Event</th><th>Venue Details</th></tr><tr><td>1</td><td>12 February</td><td>Waltz with Strauss</td><td>Main Hall</td></tr><tr><td>2</td><td>24 March</td><td>The Obelisks</td><td>West Wing</td></tr><tr><td>3</td><td>15 February</td><td>Kolidoscop</td><td>Reception Hall</td></tr><tr><td>4</td><td>24 March</td><td>The data center</td><td>UDM</td></tr></tbody></table>'

If you want to use tpl/Ext.XTemplate config in panel then you need to set tpl like below example

tpl: new Ext.XTemplate(
    //start table
    '<table class="x-date-table">',
    //Header of my table
    '<tr>',
    '<th>SNo.</th>',
    '<th>Date</th>',
    '<th>Event</th>',
    '<th>Venue Details</th>',
    '</tr>',
    //Looping insdie tpl for creating multiple row depend on data
    '<tpl for=".">', //Start loop tpl
    '<tr>',
    '<td>{#}</td>',
    '<td>{date}</td>',
    '<td>{event}</td>',
    '<td>{venue}</td>',
    '</tr>',
    '</tpl>', //End loop tpl
    '</table>' //Close table
)

在这个 FIDDLE 中,我使用与上述相同的方式创建了一个演示。希望这对您有所帮助或指导您实现您的要求。

代码片段

Ext.application({
    name: 'Fiddle',

    launch: function () {
        //Array of data for testing/example
        var data = [{
            date: '12 February',
            event: 'Waltz with Strauss',
            venue: 'Main Hall'
        }, {
            date: '24 March',
            event: 'The Obelisks',
            venue: 'West Wing'
        }, {
            date: '15 February',
            event: 'Kolidoscop',
            venue: 'Reception Hall'
        }, {
            date: '24 March',
            event: 'The data center',
            venue: 'UDM'
        }];
        //Panel show data with XTemplate
        Ext.create('Ext.panel.Panel', {
            renderTo: Ext.getBody(),
            fullscreen: true,
            title: 'Example of XTemplate in Panel',
            tpl: new Ext.XTemplate(
                //start table
                '<table class="x-date-table">',
                //Header of my table
                '<tr>',
                '<th>SNo.</th>',
                '<th>Date</th>',
                '<th>Event</th>',
                '<th>Venue Details</th>',
                '</tr>',
                //Looping insdie tpl for creating multiple row depend on data
                '<tpl for=".">', //Start loop tpl
                '<tr>',
                '<td>{#}</td>',
                '<td>{date}</td>',
                '<td>{event}</td>',
                '<td>{venue}</td>',
                '</tr>',
                '</tpl>', //End loop tpl
                '</table>' //Close table
            ),
            data: data
        });

        /*This function will create html base on data and return
         * @param {Array} arr contain of data/records
         * @return {String/HTML}
         */
        function doGetHtml(arr) {
            let html = `<table class="x-date-table"><tr><th>SNo.</th><th>Date</th><th>Event</th><th>Venue Details</th></tr>`;

            arr.forEach((item, index) => {
                html += `<tr><td>${index+1}</td><td>${item.date}</td><td>${item.event}</td><td>${item.venue}</td></tr>`;
            });
            return `${html}</table>`
        }

        //Panel show data with HTMl
        Ext.create('Ext.panel.Panel', {
            renderTo: Ext.getBody(),
            margin: '20 0 0 0',
            fullscreen: true,
            title: 'Example of HMTL in Panel',
            html: doGetHtml(data)
        });
    }
});