-
21 Dec 2011 1:30 AM #1
Error on Ext.JSON.encode "Uncaught RangeError: Maximum call stack size exceeded"
Error on Ext.JSON.encode "Uncaught RangeError: Maximum call stack size exceeded"
Hello!
I receive this error :
"Uncaught RangeError: Maximum call stack size exceeded"
when I am trying to encode an array of records of a model data.
This is the code :
Code:Ext.define('nuovaFattura', { extend: 'Ext.data.Model', fields: [ {name: 'IQTA', type: 'int'}, {name: 'VCODICE', type: 'string'}, ] }); var nuovaFatturaStore = Ext.create('Ext.data.Store', { model: 'nuovaFattura', data: {'items':[ {"IQTA":"1", "VCODICE":"Clicca per inserire codice"} ]}, proxy: { type: 'memory', reader: { type: 'json', root: 'items' } } }); . . . . . xtype: 'button', text: 'Aggiungi', handler: function() { var rec = new nuovaFattura({ IQTA: 1, VCODICE: 'Clicca per inserire codice' }); nuovaFatturaStore.insert(0, rec); } . . . . . records = nuovaFatturaStore.getRange(); jsonRecords = Ext.JSON.encode(records);
So first I define the model,after the store ,in local mode,and after I fill the store with some data.
Then I take all the records of the store by the getRange() and I have an array of model (the records)
When I try to encode this array i receive the error!!!!
Why???
I have seen a report bug on this error but I have already download and using the ext-4.0.7 version!!!(that could be fixed with the error...),but the error persist......
Why???
It's a mine error or what????
Please help...
Thanks
-
21 Dec 2011 7:33 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
The bug report you say you saw... did it say it was fixed?
Also, you are going to have a lot of overhead when encoding an Array of Models... Don't you just want to encode the data Object of each Model?Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Dec 2011 7:53 AM #3
Hi!!!!
Yes it say fixed I think...
here : http://www.sencha.com/forum/showthre...exceeded/page3
I dowload tha 4.0.7 and it say fixed in the 4.0.6 ....
And yes ,I have many of this error :
And Yes!I want toCode:"Uncaught RangeError: Maximum call stack size exceeded encodeString doEncode encodeObject doEncode encodeObject doEncode encodeObject doEncode"
encode the data Object of each Model!
It is not right to do in my way???
Now I have resolved doing this :
and sending the string encoded by AJAX to the php server where I decode and rebuild the array of objects.Code:records = nuovaFatturaStore.getRange(); jsonRecords = ''; for(x=0;x<records.length;x++){ jsonRecords = jsonRecords+Ext.JSON.encode(records[x].data)+','; }
Is there another way?
Thanks a lot and sorry...I am really new to Sencha.
Regards
-
21 Dec 2011 8:18 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Right now you are encoding the Model not the data so you have fields, there is a store reference that is then getting encoded. You need to loop through that array and add the data object to another array and encode that array.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Dec 2011 8:20 AM #5
Mmmm...sorry I don't understand....
Could you explain more?
Could you give me an example???
Thanks a lot!!!
-
21 Dec 2011 8:25 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Thought that was pretty good.
So you have an array of Models... you have to loop through it:
But you only want the data property:Code:var models = store.getRange(), m = 0, mNum = models.length; for (; m < mNum; m++) { ... }
Now the data array is an array of Objects that you would want to encode.Code:var models = store.getRange(), m = 0, mNum = models.length, data = []; for (; m < mNum; m++) { data.push(models[m].data); }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Dec 2011 3:22 AM #7
Hi mitchell!!!
Now I understand!
Doing your way is more CLEAN.
I was doing the encode of every records of the model array and after pass the string to the server I rebuild it in a correct JSON format and after decoded it.
But your way is more simple.I will use it!!!
So thanks a lot about this solution!Code:records = nuovaFatturaStore.getRange(); dataArray = []; for(x=0;x<records.length;x++){ dataArray.push(records[x].data); } jsonRecords = Ext.JSON.encode(dataArray);
But how about the error I have talked up???It is fixed or will be?
Should be possible to do the encode of the model's array or not?
Really thanks a lot and I want to say Merry Christmas and a Happy New Year to you and all the Sencha Team!!!
Bye
-
21 Sep 2012 5:30 AM #8
I think you can achieve the same result using:
Ext.pluck(store.data.items, 'data');


Reply With Quote