ExtJS: 在Ext.grid.property.Grid中显示模型

5
我希望在属性网格中显示持久字段(在我的模型文件中定义的那些)。 enter image description here 属性网格:
Ext.define('ATCOM.view.InspectorProperties', {
    extend : 'Ext.grid.property.Grid',
    alias : 'widget.inspectorProperties',
    cls : 'property-grid',
    height : 150,
    listeners : {
        beforerender : function() {
            // Rename the first column
            var cols = this.getView().getHeaderCt().getGridColumns();
            cols[0].setText("Property");
        },
        beforeedit : function(e) {
            // Read-only
            return false;
        }
    },
    source : {} // Start with no items
});

我在选择事件中(在控制器中)这样载入条目,其中record是我们的模型对象,getInfo()是属性网格:

var source = {};
source.id = record.get('id');
source.start = record.get('start');
source.end = record.get('end');

this.getInfo().setSource(source);

模型:

Ext.define('ATCOM.model.Shift', {
    extend : 'Ext.data.Model',
    fields : [ 'id', {
        name : 'start',
        type : 'date',
    }, {
        name : 'end',
        type : 'date',
    }, 'position', 'controller' ],
    hasMany : {
        model : 'ATCOM.model.ShiftAlloc',
        name : 'allocations'
    }
});

有没有更好的方法,让所有非关联字段(在我的情况下不包括allocations)自动发送到属性网格?可能也可以使用ATCOM.model.Shift.getFields()读取字段,并迭代检查persistent:false;以保留其余键,但是我如何从实例中获取类引用 - 也就是说,如何从ATCOM.model.Shift的一个实例中获取它的类,以便我可以调用getFields()?
编辑:
查找类名的方法:http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Base-static-method-getName

+1,你的代码展示了如何更改列名并使其只读...太棒了! - Dave
干杯,需要一些挖掘才能找到:\ - Aram Kocharyan
1个回答

1

用setSource(record.data)可能会起作用。我现在只是在尝试玩这个;虽然它似乎显示了正确的信息,但您可能会失去对启用哪些字段进行编辑等细节的控制。


是的,这里唯一的问题是它可能显示比 data 中需要的更多信息,例如 CSS 类、父 ID 等。 - Aram Kocharyan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接