问题
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