gpt4 book ai didi

extjs - 如何在 extjs 4.1 中使用包含图像的组合

转载 作者:行者123 更新时间:2023-12-02 17:42:15 26 4
gpt4 key购买 nike

我尝试用图像(或其他东西)创建一个组合,当我选择一个选项时,组合中的值有一些选项。

我创建了一个组合框,如下所示:

enter image description here

但是当我选择一个看起来像这样的选项时:

enter image description here

这是我的代码 http://jsfiddle.net/QZqeK/

// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [{
"abbr":"AL",
"name":"<img src='http://icons.iconarchive.com/icons/famfamfam/silk/16/folder-picture-icon.png'>"
},
{
"abbr":"AK",
"name":"<img src='http://icons.iconarchive.com/icons/famfamfam/silk/16/folder-picture-icon.png'>"
},
{
"abbr":"AZ",
"name":"<img src='http://icons.iconarchive.com/icons/famfamfam/silk/16/folder-picture-icon.png'>"
}]
});

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose',
store: states,
tpl: '<tpl for="."><div class="x-boundlist-item" >{name} {abbr}</div></tpl>',
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{name} {abbr}',
'</tpl>'
),
queryMode: 'local',
displayField: 'abbr',
valueField: 'abbr',
renderTo: Ext.getBody()
});

如何解决?谢谢!

最佳答案

您将无法使用模板解决此问题。 ComboBox 的显示值用作文本输入字段的值,这就是您的 HTML 按字面显示的原因。

这可能有点 hackish,但您可以监听 select 事件并直接在 inputEl 上更新一些样式。

请注意,此样本是一个近似值。您可能需要进行试验才能获得所需的效果。

var urlBase = 'http://icons.iconarchive.com/icons/famfamfam/silk/16/';

// Don't use image tag, just URL of icon
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [
{abbr: 'AL', name: urlBase + 'folder-picture-icon.png'},
{abbr: 'AK', name: urlBase + 'folder-picture-icon.png'},
{abbr: 'AZ', name: urlBase + 'folder-picture-icon.png'}
]
});

Ext.create('Ext.form.field.ComboBox', {
fieldLabel: 'Choose',
store: states,
queryMode: 'local',
displayField: 'abbr',
valueField: 'abbr',
renderTo: Ext.getBody(),
tpl: [
'<tpl for=".">',
'<div class="x-boundlist-item">',
'<img src="{name}"/>{abbr}',
'</div>',
'</tpl>'
],
listeners: {
select: function (comboBox, records) {
var record = records[0];
comboBox.inputEl.setStyle({
'background-image': 'url(' + record.get('name') + ')',
'background-repeat': 'no-repeat',
'background-position': '3px center',
'padding-left': '25px'
});
}
}
});

关于extjs - 如何在 extjs 4.1 中使用包含图像的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19268128/

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