Search code examples
javascriptextjssencha-touch

Remove record by id from store in extJs/ Sencha


I Want to Remove record by Id. Eg. store contains RoleId, RoleName fieds.

there are many records in store, I have RoleId to remove/delete record from store. belove code I already tried but not working.. can you give me some suggestions for this.

  roleId = Ext.getStore('userStore').first().data.roleId;
                    var roleStore = Ext.getStore('userStore').first().companies().first().roles();
                    roleStore.remove(roleStore.findRecord('roleId', roleId));

And also tried...

  roleId = Ext.getStore('userStore').first().data.roleId;
                    var roleStore = Ext.getStore('userStore').first().companies().first().roles();
                    roleStore.removeAt(roleStore.find('roleId', roleId));

Solution

  • You can directly try this,

    roleId = Ext.getStore('userStore').first().data.roleId;
    var roleStoreItems = Ext.getStore('userStore').first().companies().first().roles().data.items;
    roleStoreItems.forEach( function(item,index){
    if(item.data.roleId==roleId){
    roleStoreItems.remove(index);
    }
    });