gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:35:13 25 4
gpt4 key购买 nike

我有一个继承自Ext.grid.Panel的类,并使用该类中的方法来显示一个面板,其中包括两个项目:一个listtoolbar 类和 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 01Img 02

最佳答案

@Nuri,在您的代码中您设置 html使用Ext.XTemplate 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)
});
}
});

关于javascript - ExtJS无法正确显示Ext.panel.Panel的html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48563540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com