Results 1 to 3 of 3

Thread: how to write/update/save json file which is read from proxy in extjs store

  1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    14
    Vote Rating
    0
      0  

    Default how to write/update/save json file which is read from proxy in extjs store

    This is my code


    Ext.require([
    'Ext.form.*'
    //'Ext.layout.container.Column',
    //'Ext.tab.Panel'
    //'*'
    ]);

    Ext.onReady(function() {
    Ext.QuickTips.init();

    var bd = Ext.getBody();


    bd.createChild({tag: 'h2', html: 'Form 1 - Very Simple'});

    var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';

    Ext.define('app.formStore', {
    extend: 'Ext.data.Model',
    fields: [
    {name: 'countryid'},
    {name: 'countryid1'},

    ]
    });

    var myStore = Ext.create('Ext.data.Store', {
    model: 'app.formStore',
    proxy: {
    type: 'ajax',
    url : 'org.json',
    reader:{
    type:'json',
    getResponseData: function(response) {
    var data, error;

    try {
    data = response.responseText || '';
    if(data.match(/^[^{]*(\{.*\})[^}]*$/)){
    data = RegExp.$1;
    }
    data = Ext.decode(data);
    return this.readRecords(data);
    } catch (ex) {
    error = new Ext.data.ResultSet({
    total : 0,
    count : 0,
    records: [],
    success: false,
    message: ex.message
    });
    this.fireEvent('exception', this, response, error);
    Ext.Logger.warn('Unable to parse the JSON returned by the server');
    return error;
    }
    }


    }
    },
    autoLoad:true,
    listeners: {
    load: function() {
    //var form = Ext.getCmp('loginForm');
    //alert(myStore.data);
    //for(var i in myStore.data)
    //console.log(i+'=='+myStore.data[i]);

    //form.loadRecord(myStore.data.first());

    /* var form = Ext.getCmp('loginForm');
    form.loadRecord(myStore.data.first());*/

    var form = Ext.getCmp('loginForm');
    form.getComponent('countryid').setValue( myStore.proxy.reader.countryid);
    form.getComponent('countrycode').setValue( myStore.proxy.reader.jsonData.countrycode);

    form.loadRecord(myStore.data.first());
    }

    }});


    var testForm = Ext.create('Ext.form.Panel', {
    width: 500,
    height:250,
    renderTo: Ext.getBody(),
    title: 'Country Form',
    // model:'app.formStore',
    id:'loginForm',
    store:myStore,
    waitMsgTarget: true,
    fieldDefaults: {
    labelAlign: 'right',
    labelWidth: 85,
    msgTarget: 'side'
    },
    //items: [{

    // xtype: 'fieldset',
    items: [

    {
    xtype:'textfield',
    fieldLabel: 'CODE',
    id:'countryid',
    hidden:false

    }, {
    xtype:'textfield',
    fieldLabel: 'CODE',
    id: 'countrycode'
    }, {
    xtype:'textfield',
    fieldLabel: 'COUNTRY',
    id: 'countryname'
    }],
    // }],
    buttons:[
    {
    items:'button',
    text:'save'
    },
    {
    items:'button',
    text:'cancel'
    },

    ]

    });





    //this.testForm.getForm().loadRecord(app.formStore);
    });

    json is org.json
    {"countryid":1,"countrycode":"US","countryname":"United States"}

    if i edit in country id field that should be retrieved to to format of json and update in json when i click save button same for cancel also i didnt written clear of buttons please let me if anybody knows

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,409
    Answers
    716
    Vote Rating
    504
      0  

    Default

    Where do you want to write/save the json file to?

    Scott.

  3. #3
    Sencha User
    Join Date
    May 2016
    Posts
    1
    Vote Rating
    0
      0  

    Default

    Can we write the json on local data.json file on clientside?

    Say On click of a button I want to persist data on local user machine in a.json file, can that be achieved using any config ?

Posting Permissions

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