3
안녕하세요 Ember View에서 캔버스 '2D'컨텍스트를 얻는 방법은 무엇입니까? 다음 코드는 작동하지 않습니다. dom의 캔버스 요소를 가져 오지만 '2d'의 컨텍스트는 가져 오지 않습니다. 귀하의 예를 다음Ember.js and Canvas
는App.Canvas = Ember.View.extend({
tagName: 'canvas',
quader: function() {
return this.get('controller.model');
}.property('controller.model'),
didInsertElement: function(){
var canvas = this.$('#id'); // get the Element
var ctx = canvas.getContext('2d'); // --> get Error
// Filled triangle
ctx.beginPath();
ctx.moveTo(25,25);
ctx.lineTo(105,25);
ctx.lineTo(25,105);
ctx.fill();
// Stroked triangle
ctx.beginPath();
ctx.moveTo(125,125);
ctx.lineTo(125,45);
ctx.lineTo(45,125);
ctx.closePath();
ctx.stroke();
}
});
감사합니다. 그래, 그것은 위대한 작품 :) – abuder