2012-11-18 78 views
0

我是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(); 
}}); 
+0

你是什麼意思與 '中期'?你卡在哪裏? – sra

+0

@sra:保存時,我可以看到POST請求正在進行,但沒有響應,在螢火蟲中它顯示'Aborted'。 – Supereme

+0

我認爲你的服務器代碼有問題,請檢查使用POST請求和響應頭髮送的數據。 –

回答

0

嘗試添加到店代理:writer:new Ext.data.JsonWriter()

0

試試這個方法

grid.insert(rowIndex,[values])