summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative/javascriptblocks.qdoc
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-01-27 05:34:34 (GMT)
committerBea Lam <bea.lam@nokia.com>2011-01-27 05:37:10 (GMT)
commit43b8305367156c1ceb09eb4a056bdae3f325b5eb (patch)
tree8d792838920476495cba22c802939b719619a55d /doc/src/declarative/javascriptblocks.qdoc
parent357f1163f75e4b23a5b87dd6b3d742d167cd9c10 (diff)
downloadQt-43b8305367156c1ceb09eb4a056bdae3f325b5eb.zip
Qt-43b8305367156c1ceb09eb4a056bdae3f325b5eb.tar.gz
Qt-43b8305367156c1ceb09eb4a056bdae3f325b5eb.tar.bz2
Allow property bindings to be easily created from JavaScript
Properties can now be assigned a function that returns the binding value. Task-number: QTBUG-14964 Reviewed-by: Aaron Kennedy
Diffstat (limited to 'doc/src/declarative/javascriptblocks.qdoc')
-rw-r--r--doc/src/declarative/javascriptblocks.qdoc42
1 files changed, 10 insertions, 32 deletions
diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc
index d221205..65877f9 100644
--- a/doc/src/declarative/javascriptblocks.qdoc
+++ b/doc/src/declarative/javascriptblocks.qdoc
@@ -200,37 +200,12 @@ Likewise, the \l {Component::onDestruction} attached property is triggered on
component destruction.
-\section1 Property Assignment vs Property Binding
+\section1 JavaScript and Property Binding
-When working with both QML and JavaScript, it is important to differentiate between
-QML \l {Property Binding} and JavaScript value assignment. In QML, a property
-binding is created using the \e {property: value} syntax:
+Property bindings can be created in JavaScript by assigning the property with a \c function
+that returns the required value.
-\code
-Rectangle {
- width: otherItem.width
-}
-\endcode
-
-The \c width of the above \l Rectangle is updated whenever \c otherItem.width changes. On the other
-hand, take the following JavaScript code snippet, that runs when the \l Rectangle is created:
-
-\code
-Rectangle {
-
- Component.onCompleted: {
- width = otherItem.width;
- }
-}
-\endcode
-
-The \c width of this \l Rectangle is \e assigned the value of \c otherItem.width using the
-\e {property = value} syntax in JavaScript. Unlike the QML \e {property: value} syntax, this
-does not invoke QML property binding; the \c rectangle.width property is set to the value
-of \c otherItem.width at the time of the assignment and will not be updated if that value
-changes.
-
-See \l {Property Binding} for more information.
+See \l {Binding Properties from JavaScript} for details.
\section1 Receiving QML Signals in JavaScript
@@ -315,10 +290,13 @@ 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
+\o The value of \c this is currently undefined in QML in the majority of contexts
+
+The \c this keyword is supported when \l {Binding Properties from JavaScript}
+{binding properties from JavaScript}. In all other situations, the value of
+\c this is undefined in QML.
-The value of \c this is undefined in QML. To refer to any element, provide
-an \c id. For example:
+To refer to any element, provide an \c id. For example:
\qml
Item {