Datapath

出自OpenFace

跳转到: 导航, 搜索

目录

<datapath>

The binder between data and nodes. JavaScript: LzDatapath

Extends Datapointer

Datapaths are used to merge data hierarchies with the hierarchy of an OpenLaszlo application. This is done using the the XPath syntax supported by LzDatapointer. 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 replication manager takes over the view's spot in its parent.

A node can only have one datapath, and datapaths always have the name datapath. Additional options available on datapath such as pooling and lazy replication are specified by writing the <datapath> tag as a separate node. Example 1. Mapping data to views using datapaths.

<canvas height="120">
<dataset name="myData">
  <myXML>
      <person show="simpsons">
        <firstName>Homer</firstName>
        <lastName>Simpson</lastName>
      </person>
      <person show="simpsons">
        <firstName>Marge</firstName>
        <lastName>Simpson</lastName>
      </person>
      <person show="simpsons">
        <firstName>Montgomery</firstName>
        <lastName>Burns</lastName>
      </person>
    </myXML>
</dataset>  
 <view name="myTable">
  <simplelayout axis="y" />
  <view name="rowOfData" datapath="myData:/myXML[1]/person">
    <simplelayout axis="x" />
    <text datapath="firstName/text()" /> 
    <text datapath="lastName/text()" /> 
    <text datapath="@show" />
  </view>
</view>   
</canvas>


Attributes inherited from Datapointer

context, ondata, onerror, p, rerunxpath, xpath

Attributes inherited from Node

id, name, oninit, parent, subnodes

Methods

setNodes()

LzDatapath.setNodes(nodes)

Normally, replication is started when a datapath xpath binding returns multiple nodes. This function overides that behavior and forces replication, and replicates over the list of nodes supplied to this function. Note that once this function is called, the replication manager is no longer actively bound to the data it replicates over by its xpath (if it had one); henceforth the replication set can *only* be controlled by calling setNodes. Parameters Name Type Desc nodes [LzDataElement] A list of LzDataElements to replicate over.


Methods inherited from LzDatapointer

addNode, addNodeFromPointer, comparePointer, deleteNode, deleteNodeAttribute, dupePointer, getDataset, getNodeAttribute, getNodeAttributes, getNodeCount, getNodeName, getNodeText, isValid, selectChild, selectNext, selectParent, selectPrev, serialize, setFromPointer, setNodeAttribute, setNodeName, setNodeText, setPointer, setXPath


Methods inherited from LzNode

childOf,  createChildren,destroy, getAttribute, init,  setAttribute,setName

Events inherited from LzDatapointer

ondata, onerror

Events inherited from Component

oninit