I just wrote up some sample for someone, that I thought I would share 
with the group.

Questions:
1) How do you turn a string into a dataset? 
2) How do I dynamically update a dataset with some new XML so that 
databound views get updated auto-magically?

The latter questions gets asked a lot.  It's a pretty nifty feature of 
OpenLaszlo.

In the example below, the buttons load an XML fragment (from a string), 
turn that into a dataelement, then update the dataset (or part of the 
dataset) with the new data:

<canvas debug="true">

<script><![CDATA[  
 
var t ="<buddylist>"+
"    <buddy name='Sarah'>"+
"        <presence msg='stepped out' status='online'/>"+
"    </buddy>"+
"    <buddy name='Adam'>"+
"        <presence msg='coding' status='online'/>"+
"    </buddy>"+
"    <buddy name='Bret'>"+
"        <presence msg='' status='offline'/>"+
"    </buddy>"+
"    <buddy name='Peter'>"+
"        <presence msg='working at home' status='online'/>"+
"    </buddy>"+
"</buddylist>";

var p = "    <buddy name='Sarah'>"+
"        <presence msg='gone for the day' status='offline'/>"+
"    </buddy>";
]]>
</script>

<dataset name="buddy_ds">
    <buddylist>
        <buddy name="Sarah">
            <presence msg="sarah's message" status="online"/>
        </buddy>
        <buddy name="Betty">
            <presence msg="betty's message" status="offline"/>
        </buddy>
    </buddylist>
</dataset>

<simplelayout inset="10" spacing="20"/>
<view layout="axis:x; spacing:10; inset:10">
    <button text="load buddylist">
        <method event="onclick">
            var de = LzDataNode.stringToLzData(t);
            buddy_ds.setChildNodes([de]);
        </method>
    </button>
    <button text="load status update">
        <datapointer id="dp" name="dp" xpath="buddy_ds:/buddylist"/>
        <method event="onclick">
            var new_de = LzDataNode.stringToLzData(p);
            var buddyname = new_de.attributes.name;
            var old_de = dp.xpathQuery("[EMAIL PROTECTED]'"+buddyname+"']");
            //Debug.write(buddyname, old_de, dp);
            old_de.parentNode.replaceChild( new_de , old_de );
        </method>
    </button>
</view>
<view id="v" datapath="buddy_ds:/buddylist">
    <simplelayout/>
    <view id="buddy" layout="axis:x; spacing:4">
        <datapath xpath="buddy" pooling="true"/>
        <view width="12" height="12" bgcolor="0xcccccc">
            <attribute name="status" value="$path{'presence/@status'}"/>
            <attribute name="bgcolor"
                value="${this.status == 'online' ? 0x009900 : 0xcccccc}"/>
        </view>
        <text datapath="@name" width="60"/>
        <text datapath="presence/@msg"/>
    </view>
</view>

</canvas>




_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

Reply via email to