简体   繁体   English

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

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

I've a class inherit from Ext.grid.Panel and using a method inside this class to display a panel which includes two items: a listtoolbar class and a Ext.XTemplate staff. 我有一个继承自Ext.grid.Panel的类,并在该类中使用一种方法来显示一个包含以下两项的panellisttoolbar类和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!
                        }
                    ]
            }
        ]
    },

It can not displaying panel's items; 它不能显示面板的项目; listtoolbar and dashtpl 's html. listtoolbardashtpl的html。 instead of that it works when the html tag is using upper panel. 而不是在html标签使用上面板时起作用。 Just the thing is displays [Object] [Object] when dashTpl function used in first panel. 当第一个面板中使用dashTpl函数时, dashTpl显示[Object] [Object]

Here is dashTpl(); 这是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>' +

What could be the reason for this? 这可能是什么原因? Thanks in advice. 感谢您的建议。

Here is Img 01 and Img 02 这是Img 01Img 02

@Nuri, In your code you are setting html using Ext.XTemplate inside of panel , this is not right way to use html config. @Nuri,在你的代码正在设置html使用Ext.XTemplate的内部panel ,这是不使用正确的方式html配置。

If you want to use html config in panel then you need to set tpl like below example 如果要在panel使用html config,则需要像下面的示例一样设置tpl

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 如果要在panel使用tpl/Ext.XTemplate配置,则需要像下面的示例一样设置tpl

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
)

In this FIDDLE , I have created a demo using same as mentioned above. 在此FIDDLE中 ,我使用与上述相同的示例创建了一个演示。 I hope this will help you or guide you to achieve your requirement. 希望这对您有所帮助或指导您达到要求。

CODE SNIPPET 代码片段

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)
        });
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM