From b4b0bdda668e9845623995c788d88a774dd52d98 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 27 Jul 2010 10:30:07 +1000 Subject: Document 'this' as undefined in QML Task-number: QTBUG-12396 Reviewed-by: Aaron Kennedy --- doc/src/declarative/javascriptblocks.qdoc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc index c41e38e..18da3d2 100644 --- a/doc/src/declarative/javascriptblocks.qdoc +++ b/doc/src/declarative/javascriptblocks.qdoc @@ -236,6 +236,31 @@ This restriction exists as the QML environment is not yet fully established. To run code after the environment setup has completed, refer to \l {Running JavaScript at Startup}. +\o The value of \c this is currently undefined in QML + +The value of \c this is undefined in QML. To refer to any element, provide +an \c id. For example: + +\qml +Item { + width: 200; height: 100 + function mouseAreaClicked(area) { + console.log("Clicked in area at: " + area.x + ", " + area.y); + } + // This will not work because this is undefined + MouseArea { + height: 50; width: 200 + onClicked: mouseAreaClicked(this) + } + // This will pass area2 to the function + MouseArea { + id: area2 + y: 50; height: 50; width: 200 + onClicked: mouseAreaClicked(area2) + } +} +\endqml + \endlist */ -- cgit v0.12