【问题标题】:Extjs 6 - How to use DataIndex in a Grid for Nested DataExtjs 6 - 如何在网格中为嵌套数据使用 DataIndex
【发布时间】:2019-03-23 18:13:27
【问题描述】:

我在这里创建了一个小提琴。我的问题是如何为 Aircraft Name 和 Operator Name 列分配 DataIndex。

https://fiddle.sencha.com/#view/editor&fiddle/2qs9

我不想这样做

{name: 'operator', type: 'auto'},
{name: 'operatorId', type: 'string', mapping:'operator.id'},
{name: 'operatorName', type: 'string', mapping:'operator.name'}

然后使用 operatorName 作为 Grid 中的 DataIndex,因为我的原始数据在数组和模式嵌套对象中更加复杂,这意味着我需要展平整个数据结构。

【问题讨论】:

    标签: javascript json extjs grid


    【解决方案1】:

    您可以在网格中使用模板列或渲染器来显示您需要的内容。

    使用模板列:

    {
            text: 'Aircraft Name',
            tpl: '{aircraft.name}',
            xtype: 'templatecolumn'
    }
    

    使用渲染器:

    {
            text: 'Aircraft Name - Second Option',
            renderer: function (v, record) {
                   return record.getAircraft() ? record.getAircraft().get('name') : null;
            }
    }
    

    小提琴示例: https://fiddle.sencha.com/#view/editor&fiddle/2qsm

    【讨论】:

    • 太棒了。谢谢:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多