Skip to content

Instantly share code, notes, and snippets.

@PEM-FR
Created September 22, 2011 14:12
Show Gist options
  • Save PEM-FR/1234866 to your computer and use it in GitHub Desktop.
Save PEM-FR/1234866 to your computer and use it in GitHub Desktop.
A function to clean an item from a dojox.data.JsonRestStore without sending a delete req to the server
unCacheItem: function(item){
// summary:
// deletes item and any references to that item from the store.
// No request will be issued serverside
// extend dojox.data.JRS, and put this function in
// item:
// item to delete
//
// If the desire is to delete only one reference, unsetAttribute or
// setValue is the way to go.
var ref = (this.service.servicePath || '') + item.id,
toDelete = new Array;
for(subItemProperty in this._index){
var subItem = this._index[subItemProperty],
subItemId = (typeof subItem == "object") ? subItem.__id || subItem.id : null,
subItemParent = subItem.__parent || null;
if(subItemProperty.indexOf(ref) != -1){
toDelete.push(subItemProperty);
}else{
if(subItemId != null && subItemId.indexOf(ref) != -1){
toDelete.push(subItemId);
}
}
if(subItemParent !== null){
if(typeof subItemParent == "array"){
var len = subItemParent.length;
while(--len > -1){
var subParentId = subItemParent[len].__id || subItemParent[len].id;
if(subParentId.indexOf(ref) != -1){
subItemParent.splice(len, 1);
}
}
}else{
var subParentId = subItemParent.__id || subItemParent.id;
if(subParentId.indexOf(ref) != -1){
(dojox.data._getStoreForItem(subItemParent) || store).unsetAttribute(subItem, "__parent");
}
}
}
}
var len = toDelete.length;
while(--len > -1){
delete(this._index[toDelete[len]]);
toDelete.splice(len, 1);
}
toDelete = null;
delete(toDelete);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment