html5 canvas and emberjs view

南楼画角 提交于 2019-12-22 01:29:50

问题


I'd like to add some drawing functionality in my ember based application. I plan to use the html5 canvas element. Basically, in my DOM I have

<canvas id="my-canvas">

And I need to get my canvas context when the DOM is loaded with

var c = document.getElementById('my-canvas')
// ... do something with c

If the canvas is represented with an Ember.View :

App.Canvas = Em.View.extend({
 tagName: 'canvas'
})

What is the equivalent of document.getElementById?


回答1:


var view = App.Canvas.create().append();
var viewContext = Ember.get(view, 'element');

viewContext will hold what you need.




回答2:


From the canvas context, you could use the $() method:

this.$('#id')

which provides a JQuery-flavored way to access elements.



来源:https://stackoverflow.com/questions/9890709/html5-canvas-and-emberjs-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!