Results 1 to 10 of 10

Thread: How can i add data into a json file?

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Location
    Venezuela
    Posts
    27
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,327
    Answers
    3884
    Vote Rating
    1297
      0  

    Default

    What do you mean add more data? Like change the file?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
      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
    Answers
    20
    Vote Rating
    13
      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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,327
    Answers
    3884
    Vote Rating
    1297
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
      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
      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
      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
      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
      0  

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •