user1234
user1234

Reputation: 3159

How to put an html inside a Ext.each() and render the value inside it- EXTJS

I want to render a span inside a forEach loop . I'm doing it this way:

var data = [5, 78, 8, 9, 6, 5];

render: function(data) {
  return [
    '<div>'
    Ext.util.Format.ellipsis(this.name, 48),
    '<span>',
    Ext.each(data, function(ct) {
      Ext.util.Format.number(ct, '0,000')
    }),
    '</span>',
    '</div>'
  ].join('');
}

however the above code is not rendering any value inside the element, if I debug it, I see the value inside ct, but while rendering nothing displays inside . Any idea how to put an html inside for loop using EXTJS?

Upvotes: 0

Views: 227

Answers (1)

Akrion
Akrion

Reputation: 18515

Try something like this:

var data = [5, 78, 8];
Ext.application({
    name: 'Fiddle',

    launch: function () {
        new Ext.panel.Panel({
            renderTo: document.body,
            width: 500,
            height: 500,
            html: data.map((x) => {
                return `<div>
                    <span>Some Name: </span>
                    <span>${Ext.util.Format.number(x, '0,000')}</span>
                </div>`
            }),
            renderTo: Ext.getBody()
        });
    }
});

Seems to work fine in this demo Sencha's Fiddle

Upvotes: 1

Related Questions