Combobox将颜色设置为特定项目

Combobox将颜色设置为特定项目

本文介绍了Extjs Combobox将颜色设置为特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法来设置组合框项目的最后一个项目(或最后两个项目)的颜色,我试图使用TPL但没有工作。这里是TPL定义与XTeplate在我更新之前定义。非常感谢。

Is there a way to set color of last item (or last two items) of combobox items, i tried to use TPL but didn't work. Here is the TPL defination with XTeplate which was defined before i updated. Thanks a lot.

var resultTplHesap103Ekod = new Ext.XTemplate(
 '<tpl for="."><div class="x-combo-list-item">',
 '<h3><span> {val}  </h3>',
 '<span style="color:blue"> {dsc}  </span>', '</div></tpl>'
);

来自@MMT,

这样的代码。

var resultTplHesap360Ekod = new Ext.XTemplate(
        '<tpl for=".">',
            '<tpl if="(xindex ) &gt; (xcount-1)">',
               '<tpl>',
                    '<div class="x-combo-list-item">',
                    '<h3> {val}  </h3>',
                    '<span style="color:red"> {dsc}  </span>',
                    '</div>',
               '</tpl>',
            '</tpl>',

            '<tpl if="(xindex ) &lt; (xcount-2)">',
               '<tpl>',
                    '<div class="x-combo-list-item">',
                    '<h3> {val}  </h3>',
                    '<span style="color:blue"> {dsc}  </span>',
                    '</div>',
               '</tpl>',
            '</tpl>',
        '</tpl>'
    );

var comboHsp360EkodHarcama = new Ext.form.ComboBox({
            fieldLabel : '',
            labelSeparator : '',
            triggerAction : 'all',
            mode : 'local',
            store : storeHesapTasinirHeskod360,
            displayField : 'dsc',
            valueField : 'val',
            emptyText : 'Damga Vergisi Türü',
            forceSelection : true,
            hidden : true,
            forceSelection : true,
            tpl : resultTplHesap360Ekod,
            width : 300,
            listClass : 'x-combo-list-item'
        });

var storeHesapTasinirHeskod360 = new Ext.data.JsonStore({
            url : '../gen/hesapTasinir.ajax',
            root : 'list',
            fields : ['dsc', 'val']
        });

现在代码工作非常感谢@MMT,最后一个项目对我重要,但现在我有另一个问题。当我选择这最后一个RED项目,它在顶部ob框中显示为黑色文本。你能帮我让它保持红色。尊敬的。

Now code is working thank a lot @MMT, the last item (for now) is red that was important for me, but now i have another problem. When i select this last RED item it appears black in text fiel at the top ob box. Could you please help me to make it remain RED. Regards.

推荐答案

试试这个

    var tpl = new Ext.XTemplate(
        '<tpl for=".">',
            '<tpl if="(xindex ) &gt; (xcount-2)">',
               '<tpl>',
                    '<div class="x-combo-list-item">',
                    '<h3> {value}  </h3>',
                    '<span style="color:red"> {name}  </span>',
                    '</div>',
               '</tpl>',
            '</tpl>',

            '<tpl if="(xindex ) &lt; (xcount-2)">',
               '<tpl>',
                    '<div class="x-combo-list-item">',
                    '<h3> {value}  </h3>',
                    '<span style="color:blue"> {name}  </span>',
                    '</div>',
               '</tpl>',
            '</tpl>',

        '</tpl>'
    );

这篇关于Extjs Combobox将颜色设置为特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:19