-
22 Jun 2012 8:37 PM #1
Unanswered: How can i add data into a json file?
Unanswered: How can i add data into a json file?
Hi Sencha Community,
I need to know how i can add more data to my json file, i have my model 'clasificacion' , store 'clasificacion' and 'clasificacion.json' this files look like this:
STORE:
MODEL: (i use the same model that another store)Code:Ext.define('myMoney.store.Clasificacion',{ extend: 'Ext.data.Store', config: { model: 'myMoney.model.TipoPago', autoLoad: true, proxy: { type: 'ajax', url: 'clasificacion.json' } } });
and my json file:Code:Ext.define('myMoney.model.TipoPago', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ] } });
So.. how i can make that my json file have another data and it will comeCode:[ { name: "Comida" }, { name: "Transporte" }, { name: "Ropa" } ]
Code:[ { name: "Comida" }, { name: "Transporte" }, { name: "Ropa" }, { name:"Example" } ]
-
24 Jun 2012 2:26 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
What do you mean add more data? Like change the file?
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.
-
25 Jun 2012 8:59 AM #3
Yeap, chage the file, i think that i need read all data and make a new file with more data.
How i can do this? Sencha Touch have any method?
-
25 Jun 2012 9:36 AM #4
http://docs.sencha.com/touch/2-0/#!/...ore-method-add
Code:var myStore = Ext.getStore('Clasificacion'); myStore.add({name: 'name1'}, {name: 'name2'});
-
25 Jun 2012 11:52 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
You can't actually change the actual file, the browser simply cannot do it. You would need a server side language to write to the file.
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.
-
26 Jun 2012 4:32 PM #6
Yes, well this is not a problem, my app need a server conection for store and procesing data, so any suggestions? any tools that you can tell me or method that i should use for do this?
-
26 Jun 2012 9:29 PM #7
I guess the solution is called PHP!
Actually I am in need to add data to a server based .json file as well but never worked with PHP before.
Therefor it would be really great if someone could post some example code!
-
28 Jun 2012 9:01 AM #8
-
30 Jun 2012 9:56 AM #9
As I mentioned in my last post, try to use a .php file to realize that.
You can call it by implementing an Ext.Ajax.Request and use the "params" option to modify the URL which will be sent to the .php file.
Within that .php file use sth like:
to get the param out of your URL.PHP Code:$testvar = $_GET['varnameFromURL']
After that open your .json file with the php methods (json_decode / json_encode) modify it and save it.
Have a look at:
http://webhole.net/2009/08/31/how-to...data-with-php/
That website helped me a lot!
Greetings
Kayakkojote
-
1 Jul 2012 3:46 PM #10
Thanks, i'll try when i finish i told you guys



Reply With Quote