1

以下是针对 ExtJS 的

所以在我看来,我正在尝试以下方法。(基本上是删除一条记录)但由于某种原因,它甚至根本不会向服务器发送“destroyRecord”调用。知道为什么会发生这种情况吗?代码如下。

请注意,下面的 module.getResults 和 module.destroyRecord 调用创建实际服务器调用的相同函数。module.getResults 被正确调用,我得到了正确的记录,但似乎无法让它进入“destoryRecord”部分。我想知道它是否与 hasMany 参数有关,但不是积极的。任何帮助都是有益的。

看法:

var record = this.down('form').getRecord();
var store = Ext.getStore('ModuleStore');
store.remove(record);

店铺:

Ext.define('MyApp.store.ModuleStore', {
extend: 'Ext.data.Store',

requires: [
    'MyApp.model.ModuleModel'
],

constructor: function(cfg) {
    var me = this;
    cfg = cfg || {};
    me.callParent([Ext.apply({
        autoLoad: true,
        autoSync: true,
        filterOnLoad: false,
        remoteFilter: true,
        remoteSort: true,
        sortOnLoad: false,
        storeId: 'module',
        model: 'MyApp.model.ModuleModel',
        buffered: true,
        listeners: {
            write: {
                fn: me.onStoreWrite,
                scope: me
            },
            remove: {
                fn: me.onStoreRemove,
                scope: me
            },
            datachanged: {
                fn: me.onStoreDataChangeD,
                scope: me
            }
        }
    }, cfg)]);
},

onStoreRemove: function(store, record, index, options) {
    console.log('remove'); // Isn't called for some reason
}

});

模型:

Ext.define('MyApp.model.ModuleModel', {
extend: 'Ext.data.Model',

uses: [
    'MyApp.model.ModuleHistoryModel'
],

idProperty: 'id',

fields: [
    {
        name: 'id',
        type: 'int'
    },
    {
        name: 'AmendmentNumber',
        type: 'string'
    },
    {
        name: 'contract_id',
        type: 'int'
    }
],

proxy: {
    type: 'direct',
    api: {
        create: module.createRecord,
        read: module.getResults,
        update: module.updateRecords,
        destroy: module.destroyRecord
},
    reader: {
        type: 'json',
        root: 'data'
    }
},

hasMany: {
    model: 'MyApp.model.ModuleHistoryModel',
    foreignKey: 'Module_id',
    name: 'history'
}
});

模块历史模型:

Ext.define('MyApp.model.ModuleHistoryModel', {
extend: 'Ext.data.Model',

uses: [
    'MyApp.model.MaintTypeModel'
],

fields: [
    {
        name: 'id',
        type: 'int'
    },
    {
        name: 'ContractNumber',
        type: 'string'
    },
    {
        name: 'MaintType_id',
        type: 'int'
    },
    {
        name: 'Module_id',
        type: 'int'
    }
],

proxy: {
    type: 'direct',
    api: {
        create: modulehistory.createRecord,
        read: modulehistory.getResults,
        update: modulehistory.updateRecords,
        destroy: modulehistory.destroyRecord
},
    reader: {
        type: 'json',
        root: 'data'
    }
},

belongsTo: {
    associationKey: 'MaintType',
    model: 'MyApp.model.MaintTypeModel',
    getterName: 'getMaintType',
    foreignKey: 'MaintType_id',
    setterName: 'setMaintType'
}
});

MainType 型号:

Ext.define('MyApp.model.MaintTypeModel', {
extend: 'Ext.data.Model',

idProperty: 'id',

fields: [
    {
        name: 'id',
        type: 'int'
    },
    {
        name: 'Type',
        type: 'string'
    }
],

proxy: {
    type: 'direct',
    api: {
        create: mainttype.createRecord,
        read: mainttype.getResults,
        update: mainttype.updateRecords,
        destroy: mainttype.destroyRecord
},
    reader: {
        type: 'json',
        root: 'data'
    }
}
});
4

1 回答 1

1

您还需要调用 store sync,以便将网格与服务器同步。

var record = this.down('form').getRecord();
var store = Ext.getStore('ModuleStore');
store.remove(record);
store.sync();

我会将文档发送给您,但它们似乎已关闭。

于 2012-10-31T04:06:00.297 回答