god1986 2009-04-30 10:23
浏览 322
已采纳

老是报缺少对象,实在看不出来那里出错了 求各位帮忙

Morik.Office.DocrecPanel = function(config) {
Morik.Office.DocrecPanel.superclass.constructor.call(this, config);

// 加上服务器上的jsp数据生成
// 生成Company类型
var proxy = new Ext.data.HttpProxy( {
    url : 'company.jsp'
});

var recordType = new Ext.data.Record.create([ {
    name : "id",
    type : "int"
},{
    name:"date",
    type:"date"
    }, {
    name : "name",
    type : "string"
}, {
    name : "add",
    type : "string"
}, {
    name : "tel",
    type : "string"
},{
    name:'indoor',
    type:'bool'
    }]);

var reader = new Ext.data.JsonReader( {
totalProperty : "results",
    root : "rows",
    id : "id"
}, recordType);

//
// // 定义store
var store = new Ext.data.Store( {
proxy : proxy,
reader : reader
});
this.store=store;
// 第二,讲一下cm,grid
var fm = Ext.form;

[color=red] var checkColumn = new Ext.grid.CheckColumn ({
header: "Indoor?",
dataIndex: 'indoor',
width: 55
});[/color]
function formatDate(value){
return value ? value.dateFormat('M d, Y') : '';
};

var cm = new Ext.grid.ColumnModel( {
    defaultSortable : true,
    defaultWidth : 100,
    columns : [ {
        header : '编号',
        dataIndex : 'id'
    }, {
        header:'日期',
        dateIndex:'date',
         renderer: formatDate,
       editor: new fm.DateField({
            format: 'm/d/y',
            minValue: '01/01/06',
            disabledDays: [0, 6],
            disabledDaysText: 'Plants are not available on the weekends'
        })
        },{
        header : '名称',
        dataIndex : 'name',
        editor: new fm.TextField({
           allowBlank: false
       })
    }, {
        header : '地址',
        width : 300,
        dataIndex : 'add',
                    editor: new fm.TextField({
           allowBlank: false
       })
    }, {
        header : '电话',
        width : 300,
        dataIndex : 'tel',
        editor: new fm.NumberField({
        allowBlank: false,
        allowNegative: false,
        maxValue: 100000
        })
    }
    ]
});


var Plant = Ext.data.Record.create([
       // the "name" below matches the tag name to read, except "availDate"
       // which is mapped to the tag "availability"
       {name: 'id', type: 'string'},
       {name: 'date', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
       {name: 'name'},
       {name: 'add', type: 'float'},             // automatic date conversions
       {name: 'tel', type: 'string'},
       {name: 'indoor', type: 'bool'}

  ]);
var grid = new Ext.grid.EditorGridPanel( {
    cm : cm,
    store : store,
    width : 1000,
    height : 400,
    autoExpandColumn:'common',

// title:'Edit Plants?',
// frame:true,
plugins:checkColumn,
clicksToEdit:1,
tbar:[{ text: 'Add Plant',
handler : function(){
var p = new Plant({
id: 'New Plant 1',
date:'',
name:'',
add: 'Mostly Shade',
tel: 0,
availDate: (new Date()).clearTime(),
indoor:false

            });
            grid.stopEditing();
            store.insert(0, p);
            grid.startEditing(0, 0);
        }}],
    loadMask:{msg:'正在载入数据,请稍等...'},
    title : '公司列表'
});



    // trigger the data store load

store.load();

this.add(grid);



// 第三、调整,tbar分页,工具栏


var checkColumn = new Ext.grid.CheckColumn();
Ext.grid.CheckColumn = function(config){
Ext.apply(this, config);
if(!this.id){
    this.id = Ext.id();
}
this.renderer = this.renderer.createDelegate(this);

};

Ext.grid.CheckColumn.prototype ={
init : function(grid){
this.grid = grid;
this.grid.on('render', function(){
var view = this.grid.getView();
view.mainBody.on('mousedown', this.onMouseDown, this);
}, this);
},

onMouseDown : function(e, t){
    if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
        e.stopEvent();
        var index = this.grid.getView().findRowIndex(t);
        var record = this.grid.store.getAt(index);
        record.set(this.dataIndex, !record.data[this.dataIndex]);
    }
}

};

}
Ext.extend(Morik.Office.DocrecPanel, Ext.Panel, {});

出错提示代码为红色标注的这段 提示为图片所示,求各位帮忙找一下错误原因 ,3Q
[b]问题补充:[/b]
TO:lovewhzlq (架构师)
按照你的写法,提示出错信息依然存在 ,且为同一错误信息,郁闷了
[b]问题补充:[/b]
TO:lovewhzlq 因为EXTJS是新上手 所以很多代码不是自己写的

var checkColumn = new Ext.grid.CheckColumn();
Ext.grid.CheckColumn = function(config){
Ext.apply(this, config);
if(!this.id){
this.id = Ext.id();
}
this.renderer = this.renderer.createDelegate(this);
};

Ext.grid.CheckColumn.prototype ={
init : function(grid){
this.grid = grid;
this.grid.on('render', function(){
var view = this.grid.getView();
view.mainBody.on('mousedown', this.onMouseDown, this);
}, this);
},

onMouseDown : function(e, t){ 
    if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){ 
        e.stopEvent(); 
        var index = this.grid.getView().findRowIndex(t); 
        var record = this.grid.store.getAt(index); 
        record.set(this.dataIndex, !record.data[this.dataIndex]); 
    } 
} 

};
这段代码就是从ext-js的范例里拿过来的 感觉是错在这里 跟上面的代码连续不上
[b]问题补充:[/b]
TO yourgame
我没用firefox 我用的是IE的插件调试的 结果差不多的吧
[b]问题补充:[/b]
TO yourgame 你给我的代码调试出来报错信息如下图所示,点击进去看到的是ext-all-debug.js里面的一段代码 ,不过想想是不会这个JS里面的错误
后来自己调试了下发现是autoExpandColumn : 'common',这段代码出的错 将这段代码注释掉后就正常 无报错了 PS:这个JS是点击左侧tree时所调用到的,装载到右边tabpanel中的代码

  • 写回答

6条回答 默认 最新

  • zhoujuan520 2009-04-30 14:31
    关注

    你没有提供company.jsp我无法继续调试

    不过可以看出来你的问题所在,我修改了一下,你测试看看

    [code="js"]Ext.ns("Morik.Office");
    Morik.Office.DocrecPanel = function(config) {
    Morik.Office.DocrecPanel.superclass.constructor.call(this, config);
    var proxy = new Ext.data.HttpProxy({
    url : 'company.jsp'
    });
    var recordType = new Ext.data.Record.create([{
    name : "id",
    type : "int"
    }, {
    name : "date",
    type : "date"
    }, {
    name : "name",
    type : "string"
    }, {
    name : "add",
    type : "string"
    }, {
    name : "tel",
    type : "string"
    }, {
    name : 'indoor',
    type : 'bool'
    }]);

    var reader = new Ext.data.JsonReader({
            totalProperty : "results",
            root : "rows",
            id : "id"
        }, recordType);
    var store = new Ext.data.Store({
            proxy : proxy,
            reader : reader
        });
    this.store = store;
    var fm = Ext.form;
    
    var checkColumn = new Ext.grid.CheckColumn({
            header : "Indoor?",
            dataIndex : 'indoor',
            width : 55
        });
    function formatDate(value) {
        return value ? value.dateFormat('M d, Y') : '';
    };
    
    var cm = new Ext.grid.ColumnModel({
            defaultSortable : true,
            defaultWidth : 100,
            columns : [{
                    header : '编号',
                    dataIndex : 'id'
                }, {
                    header : '日期',
                    dateIndex : 'date',
                    renderer : formatDate,
                    editor : new fm.DateField({
                            format : 'm/d/y',
                            minValue : '01/01/06',
                            disabledDays : [0, 6],
                            disabledDaysText : 'Plants are not available on the weekends'
                        })
                }, {
                    header : '名称',
                    dataIndex : 'name',
                    editor : new fm.TextField({
                            allowBlank : false
                        })
                }, {
                    header : '地址',
                    width : 300,
                    dataIndex : 'add',
                    editor : new fm.TextField({
                            allowBlank : false
                        })
                }, {
                    header : '电话',
                    width : 300,
                    dataIndex : 'tel',
                    editor : new fm.NumberField({
                            allowBlank : false,
                            allowNegative : false,
                            maxValue : 100000
                        })
                }]
        });
    
    var Plant = Ext.data.Record.create([{
            name : 'id',
            type : 'string'
        }, {
            name : 'date',
            mapping : 'availability',
            type : 'date',
            dateFormat : 'm/d/Y'
        }, {
            name : 'name'
        }, {
            name : 'add',
            type : 'float'
        }, {
            name : 'tel',
            type : 'string'
        }, {
            name : 'indoor',
            type : 'bool'
        }
    
    ]);
    var grid = new Ext.grid.EditorGridPanel({
            cm : cm,
            store : store,
            width : 1000,
            height : 400,
            autoExpandColumn : 'common',
            plugins : checkColumn,
            clicksToEdit : 1,
            tbar : [{
                    text : 'Add Plant',
                    handler : function() {
                        var p = new Plant({
                                id : 'New Plant 1',
                                date : '',
                                name : '',
                                add : 'Mostly Shade',
                                tel : 0,
                                availDate : (new Date()).clearTime(),
                                indoor : false
                            });
                        grid.stopEditing();
                        store.insert(0, p);
                        grid.startEditing(0, 0);
                    }
                }],
            loadMask : {
                msg : '正在载入数据,请稍等...'
            },
            title : '公司列表'
        });
    store.load();
    
    this.add(grid);
    

    }
    Ext.extend(Morik.Office.DocrecPanel, Ext.Panel, {});

    Ext.grid.CheckColumn = function(config) {
    Ext.apply(this, config);
    if (!this.id) {
    this.id = Ext.id();
    }
    this.renderer = this.renderer.createDelegate(this);
    };

    Ext.grid.CheckColumn.prototype = {
    init : function(grid) {
    this.grid = grid;
    this.grid.on('render', function() {
    var view = this.grid.getView();
    view.mainBody.on('mousedown', this.onMouseDown, this);
    }, this);
    },

    onMouseDown : function(e, t) {
        if (t.className && t.className.indexOf('x-grid3-cc-' + this.id) != -1) {
            e.stopEvent();
            var index = this.grid.getView().findRowIndex(t);
            var cindex = this.grid.getView().findCellIndex(t);
            var record = this.grid.store.getAt(index);
            var field = this.grid.colModel.getDataIndex(cindex);
            var e = {
                grid : this.grid,
                record : record,
                field : field,
                originalValue : record.data[this.dataIndex],
                value : !record.data[this.dataIndex],
                row : index,
                column : cindex,
                cancel : false
            };
            if (this.grid.fireEvent("validateedit", e) !== false && !e.cancel) {
                delete e.cancel;
                record.set(this.dataIndex, !record.data[this.dataIndex]);
                this.grid.fireEvent("afteredit", e);
            }
        }
    },
    
    renderer : function(v, p, record) {
        p.css += ' x-grid3-check-col-td';
        return '<div class="x-grid3-check-col' + (v ? '-on' : '') + ' x-grid3-cc-'
            + this.id + '">&160;</div>';
    }
    

    };[/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献