Note that there are some explanatory texts on larger screens.

plurals
  1. POExtJS store/proxy doesn't send delete method to server
    primarykey
    data
    text
    <p>I'm trying to create simple ExtJs application that manages Users and User's Roles. Set of REST services provide this functionality on back end. When I assign a new Role to a User, appropriate data store sends POST (create) requests to the service. However when I remove existing Role from a User, it's removed only from store locally without sending DELETE request to the service. Here is my code:</p> <p>Model:</p> <pre><code>Ext.define('UserRole', { extend: 'Ext.data.Model', fields: [ { name: 'Id', mapping: "Id" }, { name: 'RoleId', mapping: "RoleId" }, { name: 'UserId', mapping: "UserId" } ] }); </code></pre> <p>Store With proxy:</p> <pre><code>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); } } }); </code></pre> <p>Method that based on selected checkboxes updates the UserRole store</p> <pre><code> 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() &amp;&amp; !exists) { var newRole = Ext.create('UserRole', { RoleId: cb.inputValue, UserId: selectedUserId }); selectedUserRoleStore.add(newRole); } else if (exists &amp;&amp; !cb.getValue()) { // delete existing role var record = selectedUserRoleStore.findRecord("RoleId", cb.inputValue); selectedUserRoleStore.remove(record); } }); selectedUserRoleStore.sync(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload