未捕获的TypeError:无法读取null的属性'addCls'

时间:2014-09-02 03:50:53

标签: javascript extjs4.2

代码如下─ 我知道错误是因为这一行 -

    record.set("units",newVal);

但我无法弄清楚究竟是什么问题。 这是代码 -

    Ext.onReady(function(){

    Ext.require([ 'Ext.ux.CheckColumn']);


   Ext.create('Ext.data.Store', {
         storeId:'simpsonsStore',
         fields:['name', 'email', 'units', 'unitInformation'],
         data:{'items':[
      { 'check':false,'name': 'Lisa',   "units":"555-111-1224" , "unitInformation":"a,b,c,d" },
      { 'check':false,'name': 'Bart',   "units":"555-222-1234",  "unitInformation":"a,b,c,d"  },
      { 'check':false,'name': 'Homer',  "units":"555-222-1244", "unitInformation":"a,b,c,d"   },
      { 'check':false,'name': 'Marge',  "units":"555-222-1254" , "unitInformation":"a,b,c,d"  }
  ]},
  proxy: {
      type: 'memory',
      reader: {
          type: 'json',
          root: 'items'
      }
  }
 });

     var grid = Ext.create('Ext.grid.Panel', {
  title: 'Simpsons',
  renderTo: Ext.getBody(),
  tbar: [
    { xtype: 'button', text: 'Button 1',
      handler: function(btn){
        console.log(grid.getStore().getUpdatedRecords());
      }
    }
  ],
  store: Ext.data.StoreManager.lookup('simpsonsStore'),
  viewConfig: {markDirty: false},
  columns: [
      {
        xtype:'checkcolumn' ,id:'check',dataIndex:'check', text:'Select',
        listeners:{
          checkchange:function(checkbox, rowIndex, checked, eOpts){
            if(checked==true){
              this.up('grid').getView().getRecord(rowIndex).dirty=true;
            }
          } 
        }
      },
      { text: 'Name',  dataIndex: 'name' ,       flex : 1,},
      {
        text : 'Units',
        flex : 1,
        dataIndex : 'units',
        xtype: 'componentcolumn',
        renderer: function(value, m, record) { 
          record.dirty=false;
          if(record.get('unitInformation')==='')    
            return '';
            return {
              listeners : {
                change: function(combo,newVal,oldVal,opts) {
                  record.set("units",newVal);
                  if(record.get('check')==true)
                    record.dirty=true;
                  else
                    record.dirty=false;
                }
              },
              store: record.get('unitInformation').split(","), 
                value: value, 
                xtype: 'combobox' 
            };
          }
        }],
  buttons:[{
      text:'Create Button',
      handler:function(btn){

        var records=grid.getStore().getUpdatedRecords();
        for(i=0;i<records.length;i++){
        alert(records[i].get('name'));
        alert(records[i].get('units'));
        var s=records[i].get('name')+','+records[i].get('units');
        alert(s);
    }
      }


   }],


 });


   Ext.create('Ext.container.Viewport', {
      renderTo: Ext.getBody(),  
      items: [
     {
      width:600,
      height:500,
      layout:'fit',
      items:[grid
      ]
    }
  ]
});
});

0 个答案:

没有答案