无法在Ext 3.2.1中更改组合框背景颜色

时间:2017-11-09 10:39:56

标签: extjs combobox

嘿我正在尝试创建一个颜色选择器,我想在用户选择他想要的颜色时更改组合框背景。

我正在调用此函数:setStyle(),以设置组合框样式,但是我收到此错误:

Uncaught TypeError: Ext.getCmp(...).setStyle is not a function
    at Object.fn (...js?v=1510223645:210)
    at EXTUTIL.Event.fire (ext-all.js?v=1510223645:1735)
    at J.fireEvent (ext-all.js?v=1510223645:1484)
    at J.onSelect (ext-all.js?v=1510223645:39222)
    at J.onViewClick (ext-all.js?v=1510223645:39309)
    at EXTUTIL.Event.fire (ext-all.js?v=1510223645:1735)
    at J.fireEvent (ext-all.js?v=1510223645:1484)
    at J.onClick (ext-all.js?v=1510223645:27169)
    at HTMLDivElement.h (ext-all.js?v=1510223645:2158)

我的代码:

xtype: 'combo',
    width: 340,
    id: 'test',
    store: new Ext.data.SimpleStore({
        fields: ['text', 'color'],
        data: [
            ['Red', '#db4e4e'],
            ['Green', '#89b76e'],
            ['Blue', '#3c8787'],
        ]
    }),
    valueField: 'color',
    mode: 'local',
    editable: false,
    tpl: '<tpl for="."><div class="x-combo-list-item" style="height: 20px; background-color:{color};"></div></tpl>',
    listeners: {
        select: {
            fn: function(combo, value) {
                Ext.getCmp('test').setStyle('background', value);
            }
        },
        scope: this
    }

我已经尝试过:

this.setFieldStyle('background:#FF0000');

但它不起作用。

我该如何解决这个问题?

谢谢。

1 个答案:

答案 0 :(得分:1)

  

我该如何解决这个问题?

你可以这样解决

1) Ext.get()id返回一个组件。有关其他详细信息,请参阅Ext.util.MixedCollection.get

Ext.get('ext-gen12').setStyle({
    background:'red'
})

2) Ext.fly()获取全局共享的flyweight元素,传递的节点作为活动元素。不要存储对此元素的引用 - dom节点可以被其他代码覆盖。

Ext.fly('ext-gen12').setStyle({
   background:'yellow'
})

注意 ext-gen12是您id或任何其他combobox ID的component。您也可以传递dom元素。

我希望这可以帮助您解决问题。

相关问题