Login Register

deleteItem on ItemFileWriteStore dosent work

We used

var fruitStore=new dojo.data.ItemFileWriteStore(data);
to create a store from a json tree data.

Later we deleted one item using...
fruitStore.deleteItem(item);

When we wanted to insert the item again at a different tree node , I get a data store exception.

--- > Error: newItem() was not passed an single-valued identity'

Dosen't the delete remove the object from the tree and the datastore ???

And also when we use

items = fruitStore.getValues(parentItem,"children"); ,

to retrieve all the siblings of the deleted item,we get the deleted item back along with the others.

In short, the store retains the deleted items somewhere.

Thanks
- Raj

I have a similar problem

I have a similar problem whit deleteItem.
I need to insert in some combobox some values dynamically.
e.g. if i choose Europe in the first comoboBox the second one will contain all the states in Europe.

If i choose another continent the stat comboBox is cleaned whit deleteItem and repopulated whit the correct states.
But if i choose Europe again the state comboBox cannot be repopulated, this is the error:
Error: assertion failed in ItemFileWriteStore message=assertion failed in ItemFileWriteStore
It's like the item is still in the data store, even if i deleted it with deleteItem.

I tried to clean the store in other ways, like calling again the constructor( .. new dojo.data.ItemFileWriteStore ...) but the comboBox doesn't like it and doesn't display anything.

Any ideas? How can i *really* delete items?

I managed to do what i

I managed to do what i needed, recalling the constructor for the same store and then reassociating the store to the comboBox
e.g.

this.myStore = new dojo.data.ItemFileWriteStore({
            data: {
                identifier: 'name',
                items: []
            }
      });
          this.myCombo.store = this.myStore;
          this.myCombo.setDisplayedValue("");

And then calling a function i repopulate the comboBox whit the desired values.

My problem is resolved, but still i don't understand how deleteItem works and why it doesn't really delete items.

I believe that

I believe that ItemFileWriteStore has a "revert" method, which would let you "undelete" items deleted by mistake. I suspect that the deleted items are probably not deleted from the store, but just marked deleted (or some such)...

Further, I recently ran into

Further, I recently ran into this same problem. An item is deleted, then try to insert an item with the same "identifier" value, and get an error about the id is already in use, or some such.

After a bit of study, the ItemFileWriteStore does delete the item from the items array, but saves it in the pending items. If you then do a store.revert(), it will recover the deleted items and put them back in the items array.

To solve the problem, I (1) delete the item, (2) do a store.save(), which discards the items that were in the pending items array, and (3) insert the same item with same identifier id--no error.

but.....

but... the store.save() will send the request to server to update the store. what if the store is local only.

also you can check the items are still present in the store._arrayOfAllItems and store._arrayOfTopLevelItems.

check the lengths of these arrays after deletion, they won't decrease.

i think we should be able to have a clean delete method form store.

thanks

save works

save is the way to do this. It will clear up the stores internal 'pending' arrays. It is up to you to make sure the call to deleteItem results in real deletion in the underlying 'real' store as well (local file or database). If your store is in memory only, the just calling save() is enough.

onDelete, onNew, onSet and so on are the connections you need.

With Tree store there's a bug in 1.0.2, the 'children' arrays are not cleared in delete, but the array length stays the same, and calling each child may cause crashes because of null items in the children array. I fixed this by tweaking the Tree onDelete by myself.

Anni

question about save in ItemFileWriteStore

EDITED:

Both in this thread and

http://dojotoolkit.org/forum/dojox-dojox/dojox-grid-support/how-submit-g...

I see advice about setting up handlers for each notification event for persisting data.

What I would like to be able to do is take all the pending add's, edit's, and remove's on a save before clearing them from memory and send them off to a servlet so as to perform the appropriate database operations. I don't want to save everything. I would like for the user to be able to revert as before, and not have every operation result in a call to the server.

Would it be advisable, instead of event handling, to subclass ItemFileWriteStore and override save and have my own callback functions that serialize the _pending lists similarly to _getNewFileContentString to send a resulting string to the server. Or would something else be better.