2012-01-04 29 views
0

如果我有附加到Ext.grid.GridPanel的商店,并且我从服务器返回错误,如何将响应中的信息传递给用户?如何在ExtJS4 GridPanel中保存更改时显示错误?

因此,例如

Ext.define('BC.data.Model.DnsZoneFile', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     { name :'dnsZoneFileId'}, 
     { name :'origin'}, 
     { name :'serialNumber', type: 'int', defaultValue: 2011122001}, 
     { name :'status', defaultValue: 'PENDING_UPLOAD'}, 
     { name :'clientId', type: 'int', defaultValue: 1}, 
     { name :'ttl', type: 'int', defaultValue: 120} 
    ], 
    idProperty: 'dnsZoneFileId', 
    idgen: { 
     type: 'sequential', 
     seed: 1, 
     prefix: 'New' 
    }, 
    proxy: { 
     type: 'ajax', 
     api: { 
      create : '/dns/zone-file/xhr-put', 
      read : '/dns/zone-file/xhr-get', 
      update : '/dns/zone-file/xhr-post', 
      destroy: '/dns/zone-file/xhr-delete' 
     }, 
     reader: { 
      type: 'json', 
      root: 'zoneFiles', 
      totalProperty: 'total' 
     }, 
     writer: { 
      type: 'json', 
      allowSingle: false 
     } 
    } 
}); 

我怎么能指定一个回调来处理,如果在/dns/zone-file/xhr-put API返回某种错误?

回答

1

Ext.data.proxy.Ajax只会公开一个名为exception的事件,该事件将针对所有操作调用;但是,事件处理程序将接收导致异常的正在执行的操作。因此,你可以看看在exception事件处理create操作,如下所示:

// ... 
    proxy: { 
     type: 'ajax', 
     api: { 
      create : '/dns/zone-file/xhr-put', 
      read : '/dns/zone-file/xhr-get', 
      update : '/dns/zone-file/xhr-post', 
      destroy: '/dns/zone-file/xhr-delete' 
     }, 
     reader: { 
      type: 'json', 
      root: 'zoneFiles', 
      totalProperty: 'total' 
     }, 
     writer: { 
      type: 'json', 
      allowSingle: false 
     }, 
     // here is the event handler 
     listeners: { 
      exception: { 
       fn: function (thisProxy, responseObj, operation, eventOpts) { 
        // do error handling for 'create' operation 
        if (operation.action === 'create') { 
         // your code here 
        } 
       } 
      } 
     } 
    }, 
    // ... 

阅读Ext.data.proxy.Ajax看到代理listeners选项和exception事件的工作,以及Ext.data.Operation怎么看正在传递什么如exception事件处理程序中的operation

相关问题