向Ext.data.TreeStore树添加条目时出错

时间:2018-10-06 19:40:40

标签: javascript extjs

我使用Extjs6。将条目添加到树中时出现错误"Uncaught TypeError: Cannot read property 'internalId' of null"

我的商店:

var urlRoot = 'data?model=Storage&method=';
Ext.define('BookApp.store.StorageStore', {
    extend: 'Ext.data.TreeStore',
    model: 'BookApp.model.Storage',
    storeId: 'StorageStore',
    requires: 'BookApp.model.Storage',
    autoSync: true,
    proxy: {
            type: 'ajax',
            noCache: false,
            actionMethods: {update: 'GET',create: 'GET',destroy: 'GET'},
            api: {
                create: urlRoot + 'Create',
                destroy: urlRoot + 'Destroy',
                read: urlRoot + 'Read'
            },
            reader: {
                type: 'json',
                rootProperty: 'children',
                successProperty: 'success'
            },
           writer:{
              type:'json',
              allowSingle:false
            }
        },
    });

从服务器读取的“读取”方法返回的数据显示在树中,如下所示:

({"text": "Storage", "expanded": "true", "children": [{"text": "Title 1", "id": 9, "expanded": true, "children": [{"text": "Test 1", "id": 10, "leaf": true}, {"text": "Test 2", "id": 11, "leaf": true}, {"text": "my-record", "id": 15, "leaf": true}]}, {"text": "Title 2", "id": 12, "expanded": true, "children": [{"text": "Test 3", "id": 13, "leaf": true}, {"text": "Test 4", "id": 14, "leaf": true}]}, {"text": "Title3", "id": 16, "leaf": true}, {"text": "my-record", "id": 17, "leaf": true}]})

模型如下:

Ext.define('BookApp.model.Storage', {
    extend: 'Ext.data.Model',
    fields: [{ name: 'id', type: 'auto' },
            'id_parent_id',
            'name',
            'code',
           ]
});

在控制器中,我听着按添加按钮并向函数添加条目:

....

    saveTreeNode: function (button) {
        var win    = button.up('panel'),
            form   = win.down('form'),
            values = form.getValues();

        var store_storage = this.getStorageStoreStore('StorageStore');
        var node = [{
            "id_parent_id": 0,
            "name": "Hello Im new record",
            "code": 111
        }];

        model = Ext.create('BookApp.model.Storage', node);
        store_storage.add(model);//An error occurs during execution
        console.dir(store_storage);
    },

.....

运行store_storage.add (model);时发生错误"Uncaught TypeError: Cannot read property 'internalId' of null"

树本身显示正确,添加新记录时出现问题

以下有关此问题的文章并未为我的问题提供解决方案:

Uncaught TypeError: Cannot read property 'internalId' of undefined

Uncaught TypeError: Cannot read property 'internalId' of undefined( WHILE SORTING NODES ON EXPAND)

extjs refresh tree store

可能是什么原因引起的问题?

0 个答案:

没有答案