0

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

请在下面找到我的代码。

应用程序.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();
}});
4

2 回答 2

0

试试这个方法

grid.insert(rowIndex,[values])
于 2012-11-21T11:24:53.370 回答
0

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

于 2012-11-20T20:59:49.430 回答