使用它作为ExtJs网格存储时如何保存JSON文件 [英] How to save JSON file when use it as ExtJs grid store

查看:131
本文介绍了使用它作为ExtJs网格存储时如何保存JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了使用ExtJs功能的应用程序,我应该将其存储在json文件中。



我的商店看起来像这样:

  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'
}
}

});

其中something.json是我的数据。问题是我想要动态添加数据到我的商店,之后保存JSON文件。我通过以下方式成功添加数据:

  Grid1Store.add(data); 

其中数据是一些JS数组,但是我如何将这些数据插入到我使用的JSON文件中对于STORE并保存在此之后?



提前谢谢!

解决方案



为了能够更新数据,您应该将数据保存在数据库中,并具有PHP (或您的服务器端语言)输出文件 something.json (这将是 something.php )。 / p>

然后,您将作者配置添加到您的代理

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

您的文件 something.php 然后必须使用更改的数据更新数据库。 / p>

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!

解决方案

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.

这篇关于使用它作为ExtJs网格存储时如何保存JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆