在 Ext-js 中插入后将记录保存在网格中
我有带有商店的网格,我将记录添加到商店,并且添加到商店的数据会反映在网格上。但是刷新后它就会消失。
这是我插入记录的代码
handler: function() {
grid.getStore().insert(
0,
new ds_model({
id:0,
name:'',
dob:''
})
);
grid.startEditing(0,0);
grid.store.commitChanges();
}
})
编辑:
var store = new Ext.data.Store({
data: [
[ 11849,'ABC','29/03/90'],
[ 11456,'CDE','17/03/90'],
[ 11344,'EFG','17/07/90'],
[ 11343,'IJK','Trainee','02/06/90'],
...
I have grid with store and i add the record to the store and data being added to the store gets reflected on the grid.but after refresh it vanishes.
here is my code for inserting the record
handler: function() {
grid.getStore().insert(
0,
new ds_model({
id:0,
name:'',
dob:''
})
);
grid.startEditing(0,0);
grid.store.commitChanges();
}
})
EDIT:
var store = new Ext.data.Store({
data: [
[ 11849,'ABC','29/03/90'],
[ 11456,'CDE','17/03/90'],
[ 11344,'EFG','17/07/90'],
[ 11343,'IJK','Trainee','02/06/90'],
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还需要结束编辑,否则商店无法提交任何更改。使用 firebug 检查您的商店是否正在保存。您还可以使用 autosave: TRUE 来保存提交
You need to end your editing also otherwise there are no changes the store can commit. use firebug to check, that your store is saving. You also may use autosave: TRUE to spare the commit
根据您在最初问题中的评论,您将商店定义如下:
这不会设置任何自动持久保存到任何后端服务器。此外,您将数据硬编码到存储中,这意味着当您重新加载时,实际上每次都会将该数据放入存储中。为了方便保存和加载到后端/从后端加载,您只需按如下方式修改它:
另请注意,您将需要一个 url 来期望从此调用。这很可能是一个 php 文件。根据您在网格中插入的内容,您将需要在 php 文件中添加如下内容:
此外,您还需要一个 php 文件来加载商店。
阅读此内容和此以获得更多说明。
As per your comments in the initial question, you defined your store as follows:
This will not set up any automatic persisting to any backend server. Also, you are hard-coding data into the store, which means that when you reload, you are literally putting that data in the store every time. To make it easy to save and load to/from backend, you just need to modify it as such:
Also note that you will need a url that will expect a call from this. This will most likely be a php file. Based on what you are inserting in the grid, you will need something like this in a php file:
Also, you'll need a php file that will do the loading of the store.
Read this and this for more clarification.