记录未更新

时间:2012-11-18 06:48:50

标签: extjs extjs4 extjs4.1 extjs-mvc

我是Ext js的新手,使用Extjs 4.1.1。我试图通过编辑(View- Edit.js)来更新记录(用户模型)。但是当发送请求时,操作正在中途中止而没有完成 是否需要编写额外的代码来保存或者我的代码中存在一些缺陷?

请在下面找到我的代码。

app.js

    Ext.application({

name: 'AM',

appFolder:'app',

controllers:['Users'],

requires:['AM.view.user.List','AM.Configuration'],

launch:function(){

    Ext.create('Ext.container.Viewport',{
        layout:'fit',
        items:[{
                xtype:'userlist',
                title:'Users',
                html:'List of users will go here'
            }   
        ]
    });
}});

型号

Ext.define('AM.model.User',{
extend:'Ext.data.Model',
fields: ['id','name','email']});

商品

Ext.define('AM.store.Users',{
extend: 'Ext.data.Store',
model: 'AM.model.User',
autoLoad: true,
idProperty:'id',

proxy:{
    type:'ajax',
    url: 'data/users.json',
    api:{
        read: 'data/users.json',
        update: 'data/updateUsers.json'
    },
    reader:{
        type: 'json',
        root: 'users',
        successProperty:'success',
    }   
}});

查看

    Ext.define('AM.view.user.Edit',{

extend: 'Ext.window.Window',

alias: 'widget.useredit',

title: 'Edit User',

layout:'fit',

autoShow:'true',

initComponent: function(){

        this.items = [{

                    xtype:'form',
                    items:[{
                        xtype:'textfield',
                        name: 'name',
                        fieldLabel: 'Name'
                    },{
                        xtype:'textfield',
                        name: 'email',
                        fieldLabel: 'Email'
                    }]
            }];

        this.buttons = [{
                text:'Save',
                action:'save'
            },{
                text:'Cancel',
                scope:this,
                handler: this.close
        }]

    this.callParent(arguments);
}});  

控制器

    Ext.define('AM.controller.Users',{
extend: 'Ext.app.Controller',

views:['AM.view.user.List','AM.view.user.Edit'],

requires:['AM.view.user.List'],

stores:['Users'],

models:['User'],

init: function(){
    console.log('Initialized Users!! This happens before the application launch function is called');   
    this.control({

        'userlist':{
             itemdblclick: this.onEditUser
        },
        'useredit button[action=save]':{
            click: this.updateUser
        }

    });
},

onEditUser: function(grid,record){
    console.log('called on Edit User.. for user '+record.get('name'));
    var view = Ext.widget('useredit');
    view.down('form').loadRecord(record);
},

updateUser: function(button){
    console.log('Clcked save button');
    var win = button.up('window'),
    form = win.down('form'),
    record = form.getRecord(),
    values = form.getValues();

    record.set(values);
    win.close();
    this.getUsersStore().sync();
}});

2 个答案:

答案 0 :(得分:0)

尝试添加到商店代理:writer:new Ext.data.JsonWriter()

答案 1 :(得分:0)

尝试这种方法

grid.insert(rowIndex,[values])