PDA

View Full Version : Data binding with braces


3.14
04-26-2004, 12:17 PM
hi
i'm trying to do some very simple data binding: i want to constrain a text component's label with a global string variable.
but the following code doesn't work (the text component always displays 'not ok'....): can someone explain me why?


##################
CODE
##################

<canvas width="800" height="500" title="Test binding">

<script>
dtp="not ok";

function choose(){dtp="ok";}
</script>

<simplelayout axis="y"/>
<button onclick="choose();">Go</button>
<text text="$always{dtp}" width="200"/>

</canvas>

antun
04-26-2004, 12:50 PM
The reason is that a simple assignment:


var foo = bar;


... does not send an event to notify things that are constrained to that variable that it has changed. Use setAttribute (or if it has one you can use a setter method like setX(), setY()):


<canvas width="800" height="500" title="Test binding">
<attribute name="dtp" type="string" value="not ok" />

<simplelayout axis="y"/>

<button onclick="canvas.setAttribute('dtp','ok!')">
Go
</button>

<text text="${canvas.dtp}" width="200"/>
</canvas>


-Antun