ExtJS 6-将div类显示为文本的网格tpl

dbf7pr2w  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(151)

我正在尝试extJS文档中的Ext.grid.Grid示例。我无法理解为什么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, department: "Sales" },
        { 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我预期<div class="test">不应该显示。我是否遗漏了什么?

23c0lvtd

23c0lvtd1#

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

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

相关问题