我在 ExtJS 中有一个可编辑的网格。我从 json 文件中获取数据,并在编辑后尝试将其保存回该文件。编辑后,我单击保存并调用 Store.sync() 但它对 JSON 文件没有任何更改,并且网格被刷新回编辑之前的状态。我是 ExtJS 的新手。我在这里缺少什么,如何使它工作?
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'Pricelist', type: 'string'},
{name: 'Productfamily', type:'string'},
{name: 'Producttype', type:'string'},
{name: 'Productsubgroup', type: 'string'},
{name: 'Item', type: 'string'},
{name: 'Level', type: 'string'},
{name: 'Factor', type:'string'},
{name: 'Factorvalue', type: 'string'},
{name: 'Effstrtdate', type: 'string'},
{name: 'Effenddate', type: 'string'},
{name: 'Comments', type: 'string'}
]
});
var userStore = Ext.create('Ext.data.JsonStore', {
model: 'User',
proxy: {
type: 'ajax',
url: '/pwbench/form/products/fctrmgmt/data.json',
api: {
read: '/pwbench/form/products/fctrmgmt/data.json',
update: '/pwbench/form/products/fctrmgmt/data.json'
},
reader: {
type: 'json',
}
},
autoLoad: true
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: userStore,
title: 'Application Users',
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
columns: [....
],
tbar: [
{
text: 'Save',
handler: function() {
userStore.sync();
userStore.load();
}
}
],
});
Ext.application({
requires: ['Ext.container.Viewport'],
name: 'ExtGrid',
launch: function() {
Ext.create('Ext.container.Viewport', {
items: grid,
width: 800,
height: 600
});
}
});