1. #1
    Sencha User
    Join Date
    Jun 2012
    Location
    Venezuela
    Posts
    27
    Vote Rating
    0
    duranmla is on a distinguished road

      0  

    Default 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:

    Code:
    Ext.define('myMoney.store.Clasificacion',{	extend: 'Ext.data.Store',
    	
    	config: {
    		model: 'myMoney.model.TipoPago',
    		autoLoad: true,
    		
    		proxy: {
    			type: 'ajax',
    			url: 'clasificacion.json'
    		}
    	}
    });
    MODEL: (i use the same model that another store)
    Code:
    Ext.define('myMoney.model.TipoPago', {    extend: 'Ext.data.Model',
        
        config: {
            fields: [
                {name: 'name', type: 'string'}
            ]
        }
    });
    and my json file:

    Code:
    [	{
    		name: "Comida"
    	},
    	{
    		name: "Transporte"
    	},
    	{
    		name: "Ropa"
    	}
    ]
    So.. how i can make that my json file have another data and it will come

    Code:
    [	{
    		name: "Comida"
    	},
    	{
    		name: "Transporte"
    	},
    	{
    		name: "Ropa"
    	},
            {
                    name:"Example"
            }
    ]

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    What do you mean add more data? Like change the file?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Location
    Venezuela
    Posts
    27
    Vote Rating
    0
    duranmla is on a distinguished road

      0  

    Default


    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?

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Location
    Toronto, Canada
    Posts
    92
    Vote Rating
    12
    Answers
    20
    iSmartDevice is on a distinguished road

      0  

    Default


    http://docs.sencha.com/touch/2-0/#!/...ore-method-add

    Code:
    var myStore = Ext.getStore('Clasificacion');
    myStore.add({name: 'name1'}, {name: 'name2'});

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  6. #6
    Sencha User
    Join Date
    Jun 2012
    Location
    Venezuela
    Posts
    27
    Vote Rating
    0
    duranmla is on a distinguished road

      0  

    Default


    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?

  7. #7
    Sencha User
    Join Date
    Jun 2012
    Posts
    12
    Vote Rating
    0
    Kayakkojote is on a distinguished road

      0  

    Default


    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!

  8. #8
    Sencha User
    Join Date
    Jun 2012
    Location
    Venezuela
    Posts
    27
    Vote Rating
    0
    duranmla is on a distinguished road

      0  

    Default


    Quote Originally Posted by iSmartDevice View Post
    http://docs.sencha.com/touch/2-0/#!/...ore-method-add

    Code:
    var myStore = Ext.getStore('Clasificacion');
    myStore.add({name: 'name1'}, {name: 'name2'});
    This code i think that work for that but is'nt iSmartDevice (Or you do this somtime before?), so is like mitchellsimoens and Kayakkojote say i thnk that i need built a new json file with a server method for that.

  9. #9
    Sencha User
    Join Date
    Jun 2012
    Posts
    12
    Vote Rating
    0
    Kayakkojote is on a distinguished road

      0  

    Default


    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:
    PHP Code:
    $testvar $_GET['varnameFromURL'
    to get the param out of your URL.
    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

  10. #10
    Sencha User
    Join Date
    Jun 2012
    Location
    Venezuela
    Posts
    27
    Vote Rating
    0
    duranmla is on a distinguished road

      0  

    Default


    Thanks, i'll try when i finish i told you guys