0

i want to add data at the end of json file.I am confused.what I did is I add the following code to it but not working.

 PersonRecord= Ext.define('Persons',{
extend:'Ext.data.Model',
fields:[......]
});
 var ds=new Ext.data.Store({
    storeId: 'person',
    model: 'Persons',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: '../data.json',
        reader:{
            type: 'json',
            root:'pers'
        }
    }
    });
    .....
    'id':Ext.id(),
    'fName':fName,
    'lName':lName,
    'fatherName':fatherName,
    'nationalCode':nationalCode,
    'tell':phone
    });
    ds.add(record);
    ds.commitChanges();

but dont work. i can load data from json but can not add new record to json

2 Answers 2

1

Ext JS is not going to update the .json file for you. If you are reading from an actual .json file, you'll need to have Ext JS send the new data to your server, and then have your server write out the update .json file.

If you can get away with supporting only very bleeding edge browsers, you could also conceivably use the HTML5(ish) File API to interact with file system items--here's a walkthrough: http://www.html5rocks.com/en/tutorials/file/filesystem/

Using this approach, you could conceivably create a custom Writer that could interact with the that API to persist additions, updates, deletes, etc.

Sign up to request clarification or add additional context in comments.

1 Comment

I did a Google to see if someone's already done a custom Writer like this, but didn't see anything. Sounds like a fun weekend project :)
0

You probably have to setup a Writer for your JsonProxy:

http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.proxy.Proxy-cfg-writer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.