Datapaths are used to merge data hierarchies with the hierarchy of an
OpenLaszlo application. This is done using the the XPath syntax supported
by lz.datapointer. When a node is given a
datapath attribute, a datapath with
the given value as its XPath is created. If the datapath retrieves a
node (i.e. it doesn't terminate in an attribute getter or a
() operator) then the node is mapped to that data context
and all child nodes will implicitly share the datacontext, but no
further action is taken. If the datapath retrieves data, rather than
just a node, a few extra things happen. First, the node's
data property is set and the node's
ondata event is sent. Second, the node's
applyData method is called with the data as the
argument. In cases where a datapath matches more than one data node,
the view with the matching datapath is replicated once for each data
node that matches, and a lz.ReplicationManager takes over
the view's spot in its parent.
When a node is replicated, an LzReplicationManager takes it's place,
and an onclones will be sent when the node's clones are updated.
A node can only have one datapath, and datapaths always have the name
datapath. Additional options available on datapath such
as pooling and
replication are specified
by writing the <datapath> tag as a separate node.
Example 10. Mapping data to views using datapaths
<canvas height="120">
<dataset name="testdata">
<Monday temp="Hi 48"> Partly Cloudly </Monday>
<Tuesday temp="Hi 60"> Showers Likely </Tuesday>
<Wednesday temp="Hi 63"> Chance Showers </Wednesday>
<Thursday temp="Hi 58"> Mostly Sunny </Thursday>
<Friday temp="Hi 50"> Clear and Cold </Friday>
</dataset>
<simplelayout spacing="5"/>
<view datapath="testdata:/*">
<view>
<simplelayout axis="x"/>
<text datapath="name()"/>
<text datapath="text()"/>
<text datapath="@temp"/>
</view>
</view>
</canvas>
| Name (CSS property) | Type (tag) | Type (js) | Default | Category | |||
|---|---|---|---|---|---|---|---|
axis
|
'x'|'y' | String | 'y' | initialize-only | |||
The direction in which the replicated elements will be layed out.
|
|||||||
pooling
|
boolean | Boolean | false | initialize-only | |||
| This attribute applies to datapaths which match multiple nodes and force replication. If pooling is true, views that are data-bound to this datapath are recycled if the dataset changes. Otherwise, views are deleted when the data nodes they are bound to disappear, and created when new data nodes match the datapath. See the section on Pooling in the Guide for information about the use of this attribute. | |||||||
replication
|
'normal' | 'lazy' | 'resize' | String | 'normal' | initialize-only | |||
Determines whether to use normal or lazy replication, if the
datapath matches more than one node.
See the section on Replication
in the Guide for information about the use of this attribute.
|
|||||||
sortorder
|
string | String|Function | read/write | ||||
The order to use to sort the dataset if replication occurs. One of
"ascending" or "descending" to use built
in dictionary sort, or a function which compares two strings and
returns 1 if the strings are in order, 0
if they are the same, and -1 if they are out of
order. To change this attribute, use setAttribute('sortorder',
...).
|
|||||||
sortpath
|
string | String | read/write | ||||
An XPath to use to obtain the sort key for sorting if replication
occurs. To change this attribute, use
.setAttribute('sortpath', ...),
|
|||||||
spacing
|
number | Number | 0 | initialize-only | |||
The spacing (in pixels) between replicated views.
|
|||||||
classroot, cloneManager, data, datapath, defaultplacement, id, ignoreplacement, immediateparent, inited, initstage, name, nodeLevel, options, parent, placement, styleclass, subnodes, transition
Methods
| setNodes() |
|---|
| setSelected() |
|---|
| updateData() |
|---|
xpath ends in a terminal selector
(an attribute, text(), or name()
expression), then the datapath attempts to call its parent's
updateData method. If this method returns a
non-undefined value, the datapath sets the data element's
attribute, text, or name, respectively, to updateData's
return value. The method then calls any other updateData
on any datapaths which depend on this one for context.
In short, to make datamapping work both ways for a given UI
control, define a updateData method that returns
the value for the data mapped to the node. This is already done
for the base LzInputText class, but not
for any other LFC classes.
addNode, addNodeFromPointer, comparePointer, deleteNode, deleteNodeAttribute, dupePointer, getDataset, getNodeAttribute, getNodeAttributes, getNodeCount, getNodeName, getNodeText, getNodeType, getXPathIndex, isValid, selectChild, selectNext, selectParent, selectPrev, serialize, setFromPointer, setNodeAttribute, setNodeName, setNodeText, setPointer, setXPath, xpathQuery
animate, applyConstraintMethod, applyData, childOf, completeInstantiation, construct, createChildren, dataBindAttribute, destroy, determinePlacement, getOption, getUID, init, lookupSourceLocator, releaseConstraint, releaseConstraintMethod, searchImmediateSubnodes, searchSubnodes, setOption, setSelected, updateData
Events
Copyright © 2002-2010 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.