【问题标题】:Extjs 5 Uncaught TypeError: Cannot read property 'height' of undefinedExtjs 5 Uncaught TypeError:无法读取未定义的属性“高度”
【发布时间】:2015-12-29 06:57:24
【问题描述】:

我将 extjs 4.2.4 更改为 5.0.0,但出现此错误。

未捕获的类型错误:无法读取未定义的属性“高度” SubSectionColumn.js?_dc=1451369036732:262

loadSprites: function() {
    var chart = Ext.getCmp(this.identifier);

    //var xAxisPositionArray = [55,95,135,175];
    var xAxisPositionArray = new Array();//[55,95,175];
    var yAxisStart = 0;
    var xAxisHeight = chart.surface.height
    var sprite;
    var fromPosition;
    var toPosition;
    var width;
    var noOfBars;
    var sectionWidth = 0;
    var newWidthValue = 0;
    var tmp;
    var chart = Ext.getCmp(this.identifier);
    var storeLen =this.storeValue.getCount();   
    var teststore =this.storeValue;
    var maxVal = 0;

    for (var i =0; i<storeLen; i++){
        tmp = parseFloat(teststore.data.items[i].get('data1'));
        if (tmp >maxVal){
            maxVal=tmp;
        }
    }

    if(maxVal>0){
        width = this.widthValue;
        noOfBars = this.storeLength;//5;
        sectionWidth = parseInt(parseInt(width)/parseInt(noOfBars));
        for(var j=0;j<noOfBars;j++){            
            newWidthValue = parseInt(newWidthValue) + parseInt(sectionWidth);   
            xAxisPositionArray[j] = newWidthValue;      
        }
        var gridArray = this.gridLineArrayVal.split(",");
        for(var i=0;i<xAxisPositionArray.length;i++){
            fromPosition = parseInt(xAxisPositionArray[i]);
            toPosition = fromPosition+1;
            sprite = Ext.create('Ext.draw.Sprite', {
                type: 'path',
                path: "M"+fromPosition+" " + yAxisStart +"L"+toPosition+" "+xAxisHeight+" Z",    //if the value is "M100 40 L150 40", it's ok.
                "stroke-width": (gridArray[i]=='dotted' || gridArray[i]=='line')?"0.4":"0",
                "stroke-dasharray":(gridArray[i]=='dotted')?"4,4,2.5,4,4,4":"",
                //"stroke-dasharray":"20,20",
                stroke: "#9f9f9f",
                //style:{cursor: 'pointer'},
                surface: chart.surface
            });
            sprite.show(true);
         };
         maxVal=parseFloat(maxVal)*(0.10)+parseFloat(maxVal); //Math.round(maxVal)+1;
         chart.axes.getAt(0).maximum = maxVal;
        }
    }

【问题讨论】:

  • 请清理您帖子中的格式。谢谢!

标签: extjs5 typeerror


【解决方案1】:

chart.surface 显然是未定义的,因为这是您尝试访问 height 属性的地方。

在 ExtJS 5 中,有两个可能与此相关的重大变化。首先,他们加强了配置属性。许多现在都带有前缀,并且不能通过它们的旧名称访问。相反,您应该使用(并且之前应该使用过)访问器方法 - 例如chart.getSurface()

第二:ExtJs 4 中使用的图表库已被弃用,并已被 Sencha Charts 取代。这带来了一些重大的 API 更改。

如果没有更多细节,很难说根本原因是什么,但该错误肯定与无法访问 surface 属性有关。

【讨论】:

    猜你喜欢
    • 2017-07-20
    • 2018-01-19
    • 2021-04-28
    • 2017-07-20
    • 1970-01-01
    • 2020-03-28
    • 2023-04-11
    • 2016-04-22
    • 2015-06-08
    相关资源
    最近更新 更多