且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通常在 ExtJS 应用程序上转义 HTML 的***方法是什么?

更新时间:2023-01-12 16:32:13

一切都取决于您的用例,但我所做的是 - 在服务器端转义所有 HTML 代码,以便不会错误地忘记"地方.当这些数据需要在表单字段中加载时,这当然会产生问题,因为它们被转义了.最简单的解决方案是覆盖所有表单字段的 setValue 并使用 Extjs htmlDecode 函数,这会将这些值恢复为正常.

Everything depends on your use case, but what I do is - escape all HTML code on server side, so that there are no 'forgotten' places by mistake. That of course creates problems, when these data need to be loaded in form fields, because they are escaped. The easiest solution is to override setValue for all form fields and use Extjs htmlDecode function, which will revert these values back to normal.

Ext.override(Ext.form.field.Base, {
    setValue: function(val) {
        val = Ext.util.Format.htmlDecode(val);
        return this.callParent([val]);
    }
});