store的应用

Ext.onReady(
    //Store的创建步骤
    function()
    {
     //------------------------------------------------------------------------
     //定义Record
     var User=Ext.data.Record.create(
      [
       {name:'id',type:'int'},
       {name:'name'},
       {name:'sex',type:'int'}
      ]
     );
     
     //创建Store
     var store=new Ext.data.Store(
      {
       //url:'User.xml',//数据源
       url:'WebForm1.aspx',//数据源
       //reader:new Ext.data.XmlReader(
       reader:new Ext.data.JsonReader(
         {
          id:'id',//主键--
          totalRecords:'totalCount',//总行数                    
          //record:'row'//xml节点选择
          //cs:'cs',//测试
          root:'row'//json节点选择
         },
         User//能够解析的记录集
        )//解析器
      }
     );
     
     
     //创建简单的store-SimpleStore
     var storesex=new Ext.data.SimpleStore(
      {
       data:[[0,'男'],[1,'女']],
       fields:[{name:'id',type:'int'},{name:'name'}]
      }
     );     
     
     
     //定义Grid的表头
     var cm=new Ext.grid.ColumnModel(
      [
       {header:'姓名',dataIndex:'name',sortable:true,editor:new Ext.form.TextField()},//可排序
       {header:'性别',dataIndex:'sex',sortable:true,editor:new Ext.form.ComboBox({ 
                          store: storesex, 
                          displayField:'name',
                          valueField:'id',
                          typeAhead: true, 
                          mode: 'local', 
                          triggerAction: 'all', 
                          emptyText:'选择物品类型', 
                          selectOnFocus:true, 
                          forceSelection:true, 
                          disable:true ,
                          resizable:true 
                          })
                         },
       {header:'编号',dataIndex:'id',sortable:false}//不可排序
      ]
     );        
     
     var i=2;
     //创建Grid
     var grid=new Ext.grid.EditorGridPanel(
      {
       store:store,
       cm:cm,
       renderTo:'paneldiv',
       width:965,
       height:530,
       title:'cs',
       autoExpandColumn:2,//指定地第二列为自动拉伸列
       clicksToEdit:1,//单击一次变为可编辑,默认为二次
       loadMask:{Msg:'这个在加载数据...'},
       tbar:[{
         id:'btnAdd',
         text:'新增',
         tooltip:'新增',
         iconCls:'add',
         handler: ''
        }, '-',
        {
         text:'查询',
         tooltip:'查询',
         iconCls:'search',
         handler:function()
          {
           var i=0;
           //--可以由此生成查询模板           
           /*for(var i=0;i<User.prototype.fields.length;i++)
           {
            alert(User.getField(i).name+':'+User.getField(i).mapping+':'+User.getField(i).type);            
           }*/
          }
        }, '-',
        {
          text:'批量删除',
         tooltip:'删除',
         iconCls:'remove',
         handler:''
        }]
      }
     );
     store.load();
     //--------------------------------------------------------
     //--查询
     //--------------------------------------------------------  
     Ext.get('btn').on('click',test);   
    }
   );

posted @ 2008-07-30 18:33  kuailewangzi1212  阅读(249)  评论(0编辑  收藏  举报