Я пытаюсь создать приложение ExtJS, использующее вкладки. Я хочу иметь возможность устанавливать идентификатор div для соответствующего контейнера каждой вкладки.
У меня пока есть это:
Ext.define('EXT.view.tab.tabs', {
extend: 'Ext.container.Container',
xtype: 'tabs',
controller: 'tabcontroller',
layout: 'fit',
config: {
name: 'image'
},
items: [{
xtype: 'container',
html: '<div id = "{name}"'
}]
});
Очевидно, это не работает. Как использовать переменную в HTML?
Есть другой способ сделать это. Мне здесь явно чего-то не хватает.
Спасибо за помощь.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Поскольку вы устанавливаете имя внутри config, вы не можете получить доступ напрямую. Для этого вам нужно использовать метод initComponent(). Внутри метода вы можете получить доступ к своей конфигурации следующим образом
this.getName()
В этом Скрипка я создал демонстрацию с использованием initComponent() и viewModel.
Фрагмент кода:
//Using initComponent method set the id dynamically
Ext.define('TabsView', {
extend: 'Ext.container.Container',
xtype: 'tabs',
//controller: 'tabcontroller',
layout: 'fit',
config: {
name: 'image',
text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
},
initComponent: function() {
this.callParent();
this.add([{
xtype: 'container',
html: `<div id=${this.getName()}>${this.getText()}</div>`
}])
}
});
Ext.create({
xtype: 'tabs',
renderTo: Ext.getBody()
});
Вы также можете достичь этой же функциональности с помощью viewModel
Фрагмент кода:
//Using viewModel
Ext.define('TabsView1', {
extend: 'Ext.panel.Panel',
xtype: 'tabs1',
title: 'Using Viewmodel',
layout: 'fit',
margin: '20 0',
bodyPadding: 10,
viewModel: {
data: {
name: 'image',
text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
}
},
items: [{
xtype: 'container',
bind: '<div id = {name}>{text}</div>'
}]
});
Ext.create({
xtype: 'tabs1',
renderTo: Ext.getBody()
});
Спасибо, сэр, это очень помогло!
Вы пробовали сделать это так: html: '<div id = "' + myVar + '"> </div>'?