1

如何获取画布元素的上下文?这条线

DynamicContext = DynamicCanvas.getContext("2d"); // ERROR

抛出此错误:

TypeError: DynamicCanvas.getContext is not a function   
         DynamicContext = DynamicCanvas.getContext("2d");

源代码

html

script type="text/x-handlebars">
    {{view "App.Canvas"}}   
</script>

Ember.js

App.Canvas = Em.View.extend({
    //attrs for canvas element
    tagName: "canvas",
    attributeBindings: ['height', 'width'],
    height: 300,
    width: 300,
    faceRadius: 40,

    didInsertElement: function(){

        this.drawStaticCanvas();
        this.drawDynamicCanvas();
    },

    drawDynamicCanvas: function(){      
    // How to get the context?


    DynamicContext = DynamicCanvas.getContext("2d"); // ERROR

    // face 
    DynamicContext.beginPath();
    DynamicContext.arc(300/2, // x x,y is at the center
        300/2, // y
        100, // arc radius
        0, // starting angle
        (360 * Math.PI)/180, // ending angle
        true); // counter-clockwise
    DynamicContext.fillStyle = "#ffddee";
    DynamicContext.fill();
    DynamicContext.stroke();    
    }
});
4

0 回答 0