PDA

View Full Version : localstorage: Uncaught TypeError: Cannot call method 'create' of undefined



coolstr
20 Nov 2011, 8:19 PM
sencha touch 2 PR2
google chrome

source code:



Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function(){

Ext.define('Search', {
extend: 'Ext.data.Model',
fields: ['id', 'query']
});

//our Store automatically picks up the LocalStorageProxy defined on the Search model
var store = Ext.create('Ext.data.Store', {
model: "Search",
proxy: {
type: 'localstorage',
id : 'test-Searches'
}
});

//loads any existing Search data from localStorage
store.load();

// //now add some Searches
store.add({query: 'Sencha Touch'});
store.add({query: 'Ext JS'});
//
// //finally, save our Search data to localStorage
store.sync();
}
});


the source code form Sencha Touch Document.

error: Uncaught TypeError: Cannot call method 'create' of undefined

Christophe.firpo
21 Nov 2011, 1:29 AM
Hi,

I've the same problem, anyone could help us?

rdougan
21 Nov 2011, 11:50 PM
There are some issues with the data package in the current PR, including this bug. These issues will be fixed before the GA.

aflx
22 Nov 2011, 12:38 PM
I had the same error. This is because the proxy-property in the Ext.data.Batch is never set. As a workaround you can add this to the constructor:



if (config.hasOwnProperty) {
this.proxy = config.proxy;
}

diesalher
23 Nov 2011, 7:06 AM
I had the same error. This is because the proxy-property in the Ext.data.Batch is never set. As a workaround you can add this to the constructor:



if (config.hasOwnProperty) {
this.proxy = config.proxy;
}


Thanks! It worked

coolstr
23 Nov 2011, 11:28 PM
Thank you very much! It worked too.

Christophe.firpo
29 Nov 2011, 12:31 AM
Hi,

I would be possible to have more code because I can't understand how to use this indication?:-?

Thank you.

aflx
29 Nov 2011, 1:10 AM
You have to change the contructor of Ext.data.Batch in your sencha-js file. I did it for the sencha-touch-all-debug.js. You will find the definition of this class at line 21456. There you have to change the constructor like this:



constructor: function(config) {
var me = this;

// aflx
if (config.hasOwnProperty) {
this.proxy = config.proxy;
}

me.mixins.observable.constructor.call(me, config);
me.operations = [];
},


Hopefully this will be fixed with the next update. Sencha announced several updates to the data package.

Christophe.firpo
29 Nov 2011, 1:37 AM
=D> That's work, thank you...

samlinux
5 Jan 2012, 12:36 AM
Is this still a problem in PR 3, also affects sessionstorage, that's right ?

I think it's, but with the fix of aflx it work's

aflx
5 Jan 2012, 1:35 AM
@samlinux: yesterday I had the same issue after updateing sencha and I think you are right. Nothing changed in PR3 :(

jvaartjes
7 Jan 2012, 1:57 AM
Yes, i had the same issue in PR3. The fix works great though!
Thanks!

mblomdahl
21 Jan 2012, 10:56 AM
I had the same error. This is because the proxy-property in the Ext.data.Batch is never set. As a workaround you can add this to the constructor:



if (config.hasOwnProperty) {
this.proxy = config.proxy;
}

People like you are what makes the Internet a great place to live.

Regards,
//mblomdahl

Bunchofstring
20 Mar 2012, 7:24 AM
I enjoy working with ST2, but I am just concerned about using data package workarounds like (1) the patch to enable non-integer idProperty for models, or (2) using store.each(function(record){store.add(record).save()},this); instead of store.add(records);store.sync();

Can someone help me understand why a PR release would have problems with store.sync()? IMO, the localstorage proxy is a key feature for Sencha Touch, so I'm surprised that this patch is still required. Maybe this isn't as critical to other devs as I think, but it'd be great to have some insightful comment on circumstances where store.sync() works OOTB vs. where it doesn't.