使用自定义模型和异步加载的extJS4树网格的悲哀

Grief with extJS4 treegrid using custom model and async loading

本文关键字:extJS4 树网 网格 加载 自定义 模型 异步      更新时间:2023-09-26

我似乎无法启动并运行树网格。我已经定义了模型、商店和树网格(如下所示)。树网格显示在目标内部,数据是异步加载的(用fiddler检查,返回了两行),但树网格只显示了两行空单元格。

我尝试了调试,商店的根节点确实有两个子节点,模型数据在子节点的raw属性下(除了一些字段,如leaf和iconCl,它们也在data属性中),但树网格显示了两个空行,尽管dataIndex指向了一个合适的模型字段。

这就像树网格找不到模型定义的字段一样?!?

以下是源代码(我使用沙盒,因为我正在将其集成到salesforce vforce中,salesforce-merge字段{!}也是有效的,并且正确呈现)

Ext4.onReady(function() {
    var target = '{!$Component.childBlock.childTreeDiv}';

    Ext4.define('ConfigurationItem', {
        extend: 'Ext4.data.Model',
        fields: [
            {
            id: 'id',
            type: 'string'},
        {
            id: 'name',
            type: 'string'},
        {
            id: 'recordType',
            type: 'string'},
        {
            id: 'ciName',
            type: 'string'},
        {
            id: 'alias',
            type: 'string'},
        {
            id: 'model',
            type: 'string'},
        {
            id: 'status',
            type: 'string'},
        {
            id: 'description',
            type: 'string'},
        {
            id: 'leaf',
            type: 'bool'},
        {
            id: 'iconCls',
            type: 'string'}
        ]
    });
    var store = Ext4.create('Ext4.data.TreeStore', {
        model: 'ConfigurationItem',
        root: {
            nodetype: 'async',
            id: '{!CI__c.Id}',
            expanded: true
        },
        proxy: {
            type: 'ajax',
            url: 'json_CIChildren',
            reader: {
                type: 'json',
                root: 'children'
            }
        }
    });
    tree = Ext4.create('Ext4.tree.Panel', {
        width: document.getElementById(target).offsetWidth,
        autoHeight: true,
        title: 'Child Configuration Items',
        collapsible: true,
        titleCollapse: true,
        renderTo: target,
        rootVisible: false,
        store: store,
        multiSelect: true,
        singleExpand: true,
        columns: [
            {
            type: 'treecolumn',
            text: 'CI#',
            dataIndex: 'name'},
        {
            text: 'Type',
            dataIndex: 'recordType'}
        ]
    });
});​

json_CIChildren?_dc=1329830854458&node=a0NT0000006tYKzMAM的请求是有效的(root.id中的parentID传播正常),并返回有效的json:

{ "children" : [
         {
             "id": "a0NT0000006tswhMAA",
             "name": "CI334593834",
             "recordType": "Rack",
             "ciName": "Empty rack",
             "alias": "",
             "model": "",
             "status": "",
             "description": "",
             "leaf": "true",
             "iconCls": "x4-ciicon-Rack"
         },
         {
             "id": "a0NT0000006tYKuMAM",
             "name": "CI2345234",
             "recordType": "Service",
             "ciName": "Business Connect - Premium",
             "alias": "",
             "model": "",
             "status": "",
             "description": "",
             "leaf": "true",
             "iconCls": "x4-ciicon-Service"
         }
 ]}

我做错了什么?为什么树网格看不到name和recordType字段?

这是因为商店只看到类似NodeInterface的字段,而在数据属性中没有我的自定义数据吗?

我认为问题是您的模型字段映射不正确。每个字段的"id"属性应改为"name"属性。