ExtJs Combobox displayField编码

时间:2012-07-19 07:19:20

标签: java javascript html extjs encoding

我有一个java Web应用程序。我有一个实体类(当然在转换后)我想在ExtJs的组合框中使用。我的问题如下:

displayField中可能有包含html代码的条目。因为在使用flexjson.JSONSerializer进行序列化期间,我使用flexjson.HTMLEncoder使条目在下拉列表中可见(在屏幕因未终止的字符串文字而死亡之前)。到目前为止一切都很好。

editor.myCombo = new Ext.form.ComboBox({
    mode: 'local',
    editable: false,
    forceSelection: true,           
    triggerAction: 'all',
    store: new Ext.data.JsonStore({
        fields: ['myId', 'myName'],
        emptyItem: {'myName' : '...'},
        data: <c:out value="${form.json['myList']}" escapeXml="false"/>         
    }),
    disabled: isEditorDisabled,
    width: 75,
    listWidth: 160,
    displayField: 'myName',
    valueField: 'myId'
});

但是当我从下拉列表中选择一个项目时(所有内容都显示为Alfred </script>),显示字段会将其显示为:Alfred &lt;/script&gt;

我如何使这项工作?为什么它显示编码版本(在json请求中检索)而不是HTML?

1 个答案:

答案 0 :(得分:2)

尝试在配置中包含重写的getDisplayValue方法。只需将其设置为返回解码值,如下所示:

editor.myCombo = new Ext.form.ComboBox({
    mode: 'local',
    editable: false,
    forceSelection: true,           
    triggerAction: 'all',
    store: new Ext.data.JsonStore({
        fields: ['myId', 'myName'],
        emptyItem: {'myName' : '...'},
        data: <c:out value="${form.json['myList']}" escapeXml="false"/>         
    }),
    disabled: isEditorDisabled,
    width: 75,
    listWidth: 160,
    displayField: 'myName',
    valueField: 'myId',

    // this should return the decoded string instead
    getDisplayValue: function() {
        return Ext.String.htmlDecode(this.value);
    }
});

必须以这种方式完成的原因是因为Ext.form.field.Combo的实际字段部分确实是HTML输入元素,并且只显示直文,它不会从中生成HTML。 / p>

相关问题