store 加载异常处理与加载信息提示

时间:2021-12-05 10:50:58
  1. var msgTip = '';   // 一定要定义在使用前,且定义为全局变量
  2. /--------------------------------store---------------------------------------------------------------//
  3. window.panelStore5 = Ext.create('Ext.data.Store', {
  4. fields:[{name:'name'},{name:'preStatics',type:'int'},'mypercent'],
  5. proxy: {
  6. type: 'ajax',
  7. url: extPath+'/center!getDetailByType.action?random='+new Date().getTime()+''+'&type=5',
  8. reader: {
  9. type: 'json',
  10. root: 'humresData',
  11. totalProperty: 'totalCount'
  12. }
  13. },
  14. autoLoad: false,
  15. sorters:[{
  16. property:"name",
  17. direction:"asc"
  18. },{
  19. property:"preStatics",
  20. direction:"asc"
  21. }],
  22. listeners:{
  23. beforeload:function(store,records,successful,operation,opts){
  24. msgTip = Ext.MessageBox.show({
  25. title:'提示',
  26. width : 250,
  27. msg:'页面统计信息刷新中,请稍后...',
  28. buttons: Ext.Msg.OK
  29. });
  30. },
  31. load:function(store,records,successful,operation,opts){
  32. if(successful){
  33. Ext.Msg.alert('提示','数据加载成功!');
  34. msgTip.hide();
  35. }else{
  36. Ext.Msg.alert('提示','数据加载失败!');
  37. msgTip.hide();
  38. }
  39. }
  40. }
  41. });
  1. 服务器 返回数值 类似:{ success:true,humerdata:{name:'andy',password:123123} } //humerdata 为root

2.store 遍历二种方式

stroe.each(function(rec){

alert(rec.get('name'));//name 为fields 字段

or: alert(rec.data.name)//name 为fields 字段

})