databinding-$14.lzx
<canvas width="100%" height="200">
<dataset name="numbers"/>
<datapointer name="thetop" xpath="numbers:/"/>
<datapointer name="numptr">
<handler name="ondata" args="d">
// d is lz.DataElement object
result.update(d.nodeName)
</handler>
</datapointer>
<simplelayout spacing="5"/>
<text>Type in a number and press the button or the Enter key</text>
<view>
<simplelayout spacing="10" axis="x"/>
<edittext name="input">
<handler name="onkeyup" args="k">
if ( k == 13 ) {
parent.bSend.compute();
}
</handler>
</edittext>
<button name="bSend" text="Add">
<handler name="onclick" method="compute"/>
<method name="compute" args="ignore=null">
if(parent.input.text.length > 0){
thetop.addNode(parent.input.text)
var end = thetop.xpathQuery('*/last()')
numptr.setXPath('numbers:/*[' + end + ']')
parent.input.clearText()
}
</method>
</button>
</view>
<view height="100">
<text bgcolor="0xcecece" datapath="numbers:/*/name()"/>
<wrappinglayout axis="y" spacing="3"/>
</view>
<view>
<attribute name="sum" value="$once{0}"/>
<simplelayout axis="x"/>
<text><b>AVG: </b></text>
<text id="result" fgcolor="blue" fontstyle="bold">
<method name="update" args="v">
parent.sum += Number(v)
this.setAttribute('text', parent.sum / thetop.p.childNodes.length)
</method>
</text>
</view>
</canvas>
Cross References
Named Instances