-1

我在 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
       });

    }
    });
4

1 回答 1

0

You can't just "update the json" without any other interaction. Imagine how big of a security flaw that would be, where any http request could just update a file on your server.

You need some server side technology, PHP/Java/.NET/other to take the response and write it to the file. There are plenty of examples of this in the Ext SDK download.

于 2013-05-14T09:26:57.687 回答