问题
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