微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ExtJS6 - Grid tpl 将 div 类显示为文本

如何解决ExtJS6 - Grid tpl 将 div 类显示为文本

我正在尝试使用 reset(json_decode($_POST['tableFields'],1)); 文档中的 Ext.grid.Grid 示例。我无法弄清楚为什么 extJS 也将 tpl 元素也显示为文本。

div

Ext.create('Ext.data.Store',{ storeId:'employeeStore',fields:['firstname','lastname','seniority','department'],groupField: 'department',data:[ { firstname: "Michael",lastname: "Scott",seniority: 7,department: "Management" },{ firstname: "Dwight",lastname: "Schrute",seniority: 2,department: "Sales" },{ firstname: "Jim",lastname: "Halpert",seniority: 3,{ firstname: "Kevin",lastname: "Malone",seniority: 4,department: "Accounting" },{ firstname: "Angela",lastname: "Martin",seniority: 5,department: "Accounting" } ] }); Ext.create('Ext.grid.Grid',{ title: 'Column Template Demo',store: Ext.data.StoreManager.lookup('employeeStore'),columns: [{ text: 'Full Name',tpl: '{firstname} {lastname}' },{ xtype: 'templatecolumn',text: 'Department (Yrs)',tpl: '<div class="test">{department} {seniority}</div>' }],height: 200,width: 300,renderTo: Ext.getBody() }); 我希望 Output 不应该显示。我在这里遗漏了什么吗?

enter image description here

解决方法

在现代工具包中,单元格内容默认是 html 编码的。对于您的情况,您需要将单元格的 encodeHtml 配置设置为 false:

{
    xtype: 'templatecolumn',text: 'Department (Yrs)',tpl: '<div class="test">{department} {seniority}</div>',cell: {
        encodeHtml: false
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。