DART初心者です。言語の概要を読み、DART エディターでサンプル コードを確認しました。これまでのところ、DART でイベントを処理する方法を見つけることができませんでした。例えばonclick="call_dart_method()"
。
DART でイベントを処理するにはどうすればよいですか?
DART初心者です。言語の概要を読み、DART エディターでサンプル コードを確認しました。これまでのところ、DART でイベントを処理する方法を見つけることができませんでした。例えばonclick="call_dart_method()"
。
DART でイベントを処理するにはどうすればよいですか?
それはあなたがここのDart Checkでそれを行う方法ではありません.イベントセクションの下にあります: http://www.dartlang.org/articles/improving-the-dom/
elem.onClick.listen(
(event) => print('click!'));
また、必要に応じて変数の型を宣言できると、Dart bliss でイベントを操作できるようになることがあります。
import 'dart:html';
import 'dart:math';
class MyApplication {
MyApplication() {
CanvasElement screenCanvas;
CanvasRenderingContext2D screen;
final int WIDTH = 400, HEIGHT = 300;
Random rand = new Random();
screenCanvas = new CanvasElement();
screenCanvas
..width = WIDTH
..height = HEIGHT
..style.border = 'solid black 1px';
screen = screenCanvas.getContext('2d');
document.body.nodes.add(screenCanvas);
screenCanvas.onClick.listen((MouseEvent me) {
int
r = rand.nextInt(256),
g = rand.nextInt(256),
b = rand.nextInt(256);
double a = rand.nextDouble();
screen
..save()
..translate(me.offsetX, me.offsetY)
..rotate(rand.nextDouble() * PI)
..fillStyle = 'rgba($r,$g,$b,$a)'
..fillRect(-25, -25, 50, 50)
..restore();
});
}
}
void main() {
new MyApplication();
}