ExtJS存储/代理不向服务器发送删除方法

Gla*_*alg 0 javascript rest extjs extjs4

我正在尝试创建管理用户和用户角色的简单ExtJs应用程序.一组REST服务在后端提供此功能.当我为用户分配新角色时,相应的数据存储会向服务发送POST(创建)请求.但是,当我从用户中删除现有角色时,它仅从本地存储中删除,而不向服务发送DELETE请求.这是我的代码:

模型:

Ext.define('UserRole', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'Id', mapping: "Id" },
        { name: 'RoleId', mapping: "RoleId" },
        { name: 'UserId', mapping: "UserId" }
    ]
});
Run Code Online (Sandbox Code Playgroud)

使用代理存储:

Ext.define('UserRoleStore', {
    extend: 'Ext.data.Store',
    model: 'UserRole',

    autoload: false,

    proxy: {

        type: 'ajax',
        reader: {
            type: 'json',
            root: 'd.results'
        },        
        api: {
            read: '/accessmanager.svc/Users(\'{userid}\')/Roles?$format=json',
            create: '/accessmanager.svc/UserRoles?$format=json',
            update: '/accessmanager.svc/UserRoles?$format=json',
            destroy: '/accessmanager.svc/UserRoles?$format=json'
        },

        updateApiUrlWithUserId: function (userId) {
            this.api.read = this.api.read.replace('{userid}', userId);
        }

    }
});
Run Code Online (Sandbox Code Playgroud)

基于所选复选框的方法更新UserRole存储

    var chekboxes = Ext.ComponentQuery.query('userdetails #roleslist')[0];

    var selectedUserId = this.selectedUserId;
    var selectedUserRoleStore = this.selectedUserRoleStore;
    Ext.each(chekboxes.items.items, function (cb) {
        var exists = false;            
        Ext.each(selectedUserRoleStore.data.items, function (cs) {
            if (cs.data.RoleId === cb.inputValue) {
                exists = true;                    
            }                
        });
        if (cb.getValue() && !exists) {
            var newRole = Ext.create('UserRole', { RoleId: cb.inputValue, UserId: selectedUserId });
            selectedUserRoleStore.add(newRole);

        } else if (exists && !cb.getValue()) {
            // delete existing role
            var record = selectedUserRoleStore.findRecord("RoleId", cb.inputValue);
            selectedUserRoleStore.remove(record);                
        }
    });
    selectedUserRoleStore.sync();
Run Code Online (Sandbox Code Playgroud)

sha*_*sha 5

据推测,创建记录时,您的Id字段在服务器端分配.正确?首先尝试在模型中指定idProperty:'Id'.这个的默认值是'id'但我认为它们区分大小写.

使用idProperty ExtJs将记录识别为"脏"并且需要在服务器端更新.