dojo.data.ItemFileWriteStore.deleteItem
dojo.require("dojo.data.ItemFileWriteStore");
defined in dojo/data/ItemFileWriteStore.js
See dojo.data.api.Write.deleteItem()
Usage
function (item) (view source)
this._assert(!this._saveInProgress); this._assertIsItem(item); // Remove this item from the _arrayOfAllItems, but leave a null value in place // of the item, so as not to change the length of the array, so that in newItem() // we can still safely do: newIdentity = this._arrayOfAllItems.length; var indexInArrayOfAllItems = item[this._itemNumPropName]; var identity = this.getIdentity(item); //If we have reference integrity on, we need to do reference cleanup for the deleted item if(this.referenceIntegrity){ //First scan all the attributes of this items for references and clean them up in the map //As this item is going away, no need to track its references anymore. //Get the attributes list before we generate the backup so it //doesn't pollute the attributes list. var attributes = this.getAttributes(item); //Backup the map, we'll have to restore it potentially, in a revert. if(item[this._reverseRefMap]){ item["backup_" + this._reverseRefMap] = dojo.clone(item[this._reverseRefMap]); } //TODO: This causes a reversion problem. This list won't be restored on revert since it is //attached to the 'value'. item, not ours. Need to back tese up somehow too. //Maybe build a map of the backup of the entries and attach it to the deleted item to be restored //later. Or just record them and call _addReferenceToMap on them in revert. dojo.forEach(attributes, function(attribute){ dojo.forEach(this.getValues(item, attribute), function(value){ if(this.isItem(value)){ //We have to back up all the references we had to others so they can be restored on a revert. if(!item["backupRefs_" + this._reverseRefMap]){ item["backupRefs_" + this._reverseRefMap] = []; } item["backupRefs_" + this._reverseRefMap].push({id: this.getIdentity(value), attr: attribute}); this._removeReferenceFromMap(value, item, attribute); } }, this); }, this); //Next, see if we have references to this item, if we do, we have to clean them up too. var references = item[this._reverseRefMap]; if(references){ //Look through all the items noted as references to clean them up. for(var itemId in references){ var containingItem = null; if(this._itemsByIdentity){ containingItem = this._itemsByIdentity[itemId]; }else{ containingItem = this._arrayOfAllItems[itemId]; } //We have a reference to a containing item, now we have to process the //attributes and clear all references to the item being deleted. if(containingItem){ for(var attribute in references[itemId]){ var oldValues = this.getValues(containingItem, attribute) || []; var newValues = dojo.filter(oldValues, function(possibleItem){ return !(this.isItem(possibleItem) && this.getIdentity(possibleItem) == identity); }, this); //Remove the note of the reference to the item and set the values on the modified attribute. this._removeReferenceFromMap(item, containingItem, attribute); if(newValues.length < oldValues.length){ this.setValues(containingItem, attribute, newValues); } } } } } } this._arrayOfAllItems[indexInArrayOfAllItems] = null; item[this._storeRefPropName] = null; if(this._itemsByIdentity){ delete this._itemsByIdentity[identity]; } this._pending._deletedItems[identity] = item; //Remove from the toplevel items, if necessary... if(item[this._rootItemPropName]){ this._removeArrayElement(this._arrayOfTopLevelItems, item); } this.onDelete(item); // dojo.data.api.Notification call return true;
parameter | type | description |
---|---|---|
item |