How to save JSON file when use it as ExtJs grid store

删除回忆录丶 提交于 2020-01-16 18:27:42

问题


I have developed application which use ExtJs functionality where I should keep my store in json file.

My store looks like this:

var Grid1Store = new Ext.data.JsonStore({
    fields: [ 'Something 1', 'Something 2', 'Status' ],
    autoLoad: true,
    proxy:{
        type:'ajax',
        url:'resources/buildJsonStore/something.json',
        reader:{
             type: 'json'
        }
    }

});   

Where something.json is my data. The problem is that I want dynamically add data to my store and after that to save the JSON file. I add data successfully with this:

Grid1Store.add(data);

where data is some JS array, but how I can insert this data into JSON file which I have used for STORE and save it after that?

Thank you in advance!


回答1:


You cannot edit files in Javascript that are fetched with HTTP.

To be able to update the data, you should save your data in a database, and have PHP (or your server side language) outputting the file something.json (which would rather be something.php).

Then you add a writer configuration to your proxy, like

proxy:{
    type:'ajax',
    url:'resources/buildJsonStore/something.json',
    reader:{
         type: 'json'
    },
    writer: 'json'
}

Your file something.php will then have to update the databse with the changed data.



来源:https://stackoverflow.com/questions/19381708/how-to-save-json-file-when-use-it-as-extjs-grid-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!