简体   繁体   English

如何在EXTJS组合框中将HTML显示为文本

[英]How to display html as text inside EXTJS combo box

Paste the code blow inside Sencha fiddle . 将代码打击粘贴到Sencha小提琴中 Look at the item that reads ProblemElement. 查看读取问题元素的项目。

Ext.define('DropDownList', {
    extend: 'Ext.form.ComboBox',
    editable: false,

    alias: 'widget.dropdownlist',
    initComponent: function() {
        this.callParent([arguments]);
    },
    onRender: function() {
        this.callParent();

    }
});


var states = Ext.create('Ext.data.Store', {
    fields: ['abbr', 'name'],
    data: [

        {
            "name": "Alabama"
        }, 
        {
            "name": "Alaska"
        }, 
        {
            "name": " <input value='ProblemElement'>"
        }
    ]
});

Ext.application({

    name: 'MyApp',
    launch: function() {


        Ext.create('Ext.form.Panel', {

            items: [{
                xtype: 'dropdownlist',
                hideLabel: false,
                title: 'ComboBox Test',
                fieldLabel: 'Choose State',
                store: states,
                displayField: 'name',
                htmlEncode: true,
                renderTo: Ext.getBody()
            }]

        });
    }
});

The problem I am facing is that the item displayed in the dropdown is being rendered as HTML. 我面临的问题是,下拉列表中显示的项目正在呈现为HTML。 However after I select it it displays correctly as text ( <input value='ProblemElement'> ), the way I want it. 但是,在我选择它之后,它会正确显示为文本( <input value='ProblemElement'> ),这是我想要的方式。

The dropdown list is actually a Boundlist , and how item text is displayed is controlled by its getInnerTpl method. 下拉列表实际上是一个Boundlist ,项目文本的显示方式由其getInnerTpl方法控制。 You can customize the combo's dropdown with listConfig so that the inner text is passed through Ext.String.htmlEncode : 您可以使用listConfig自定义组合的下拉菜单, listConfig使内部文本通过Ext.String.htmlEncode传递:

listConfig: {
    getInnerTpl: function(displayField) {
        return '{[Ext.String.htmlEncode(values.' + displayField + ')]}';
    }
}

Full example: https://fiddle.sencha.com/#fiddle/rkk 完整示例: https//fiddle.sencha.com/#fiddle/rkk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM