Maybe I'm doing this wrong but this code fails for me every time:
dojo.require("dojo.data.ItemFileWriteStore");
var store = new dojo.data.ItemFileWriteStore( { url: "countries.json"} ); // from dojo/tests/data directory
// comment out this line if you want newItem to succeed.
store.fetchItemByIdentity( { identity: "ec", onItem: function(item) { console.log("found " + store.getValue(item,"name") ); } } );
var canada = store.newItem( { name: "Canada", abbr: "ca", capital: "Ottowa" } );
store.fetchItemByIdentity( { identity: "ca", onItem: function(item) { console.log("found " + store.getValue(item,"name") ); } } );
var store = new dojo.data.ItemFileWriteStore( { url: "countries.json"} ); // from dojo/tests/data directory
// comment out this line if you want newItem to succeed.
store.fetchItemByIdentity( { identity: "ec", onItem: function(item) { console.log("found " + store.getValue(item,"name") ); } } );
var canada = store.newItem( { name: "Canada", abbr: "ca", capital: "Ottowa" } );
store.fetchItemByIdentity( { identity: "ca", onItem: function(item) { console.log("found " + store.getValue(item,"name") ); } } );
It's failing with this in Firebug...
newItem() was not passed an identity for the new item
[Break on this error] throw new Error("newItem() was not passed an identity for the new item");
If I comment out the store.fetchByIdentity line, it works fine and dandy though. Peeking at the code, if fetchItemByIdentity is never called before newItem then _getIdentifierAttribute() returns 'abbr'. If fetch is called first, then _getIdentifierAttribute() returns true.
I'm still going through dojo.data so I might be wrong but this looks like a bug (running off of trunk).

code has changed - maybe test-folder helps you
hello seth,
i've tested it too, and i think the documentation was not really clear and the names have changed. have you looked in the test-folders? each part of dojo has examples in the test-subfolders.
regards,
dura4cell
Indeed I have...
I have indeed looked at the tests. In fact, I've even created a test that fails with the same error:
var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
var deferred = new doh.Deferred();
doh.assertTrue(!store.isDirty());
function onItem(item, parentInfo) {
doh.assertTrue( item !== null );
doh.assertTrue( parentInfo === null );
doh.assertTrue( store.isItem( item ));
deferred.callback(true);
}
function onError(error,request) {
deferred.errback(error);
}
// if you comment this line out, the test will pass
store.fetchItemByIdentity( { identity: "eg", onItem: onItem, onError: onError });
var onNewInvoked = false;
store.onNew = function(newItem, parentInfo) {
doh.assertTrue(newItem !== null);
doh.assertTrue(parentInfo === null);
doh.assertTrue(store.isItem(newItem));
onNewInvoked = true;
};
var canada = store.newItem({name: "Canada", abbr:"ca",captial:"Ottawa"});
doh.assertTrue(onNewInvoked);
doh.assertTrue(store.isDirty(canada));
doh.assertTrue(store.isDirty());
doh.assertTrue(store.getValues(canada,"name") == "Canada");
return doh;
},
Paste this into dojo/tests/data/ItemFileWriteStore.js and you'll see what I mean. This is running against trunk.
Let me know if the test passes for you.
I need to submit a bug.
api maybe helps
hello seth,
i have not so much experience with the ItemFileWriteStore, and i'm not sure, if it's really a bug. have you looked in the following part of documentation?
http://api.dojotoolkit.org/jsdoc/dojo/HEAD/dojo.data.ItemFileWriteStore....
also, how i understand it, you must have an folder "eg" and "ca" in the nls directory too. i have not so much time today. maybe i can make tests in the middle of the next week - if you not have resolved the issue by yourself ;-):-)
sorry for my terrible english - i'm not a native speaker...
regards,
dura4cell
It looks to me like a real bug.
Looking at the source, I think that newItem, when looking for the identity attribute, is really getting "true" as a value; looks like there's some slight confusion about whether or not the store implements the Identity API and how the actual attribute used for identity is being retrieved.
Please file a bug at trac.dojotoolkit.org (guest/guest) on it, we'll fix it.
submitted bug 6562
Sorry, I forgot to update this thread after I posted the bug, i posted it along with the test case above the other day:
http://trac.dojotoolkit.org/ticket/6562
Thanks for the replies.