Created
September 22, 2011 14:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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