Datapointer(LzDatapointer)
出自OpenFace
<datapointer>
A cursor in a dataset. JavaScript: LzDatapointer
Extends Node
A datapointer is an object that represents a pointer to a node in a LzDataset. The datapointer can be repositioned using either cursor movements calls such as selectNext, or by running an XPath request via setXPath.
Datapointers support a subset of the XPath specification, which uses a notation similar to the UNIX file-system to refer to nodes within a dataset. Once a datapointer is bound to a node in a dataset it will keep pointing to that node until it is moved. If the dataset is edited, the behavior of the datapointer will be controlled by its rerunxpath attribute. If this attribute is true (the default value), it will continue pointing to its current node as long as it is valid.
The example below demonstrates the use of some of the features of datapaths to retrieve data from a dataset. Example 1. Using a datapointer to retrieve data from a dataset
<canvas height="80">
<dataset name="mydata">
<record> This is some text
<deeper>
<deeprecord> This is a deeper level </deeprecord>
<deeprecord> It's dark down here! </deeprecord>
<deeprecord> Last deep record </deeprecord>
</deeper>
</record>
<record> This is more text </record>
<record> Exciting no? </record>
<record> The final line of text </record>
</dataset>
<simplelayout spacing="5"/>
<view fontsize="20">
<simplelayout/>
<datapointer id="mydp" xpath="mydata:/record[1]"/>
<text id="t1"> Move forward with select
<method name="reset1">
if (mydp.selectNext()) s = mydp.getNodeText();
output.setText(s);
</method>
</text>
<handler name="onkeydown" reference="LzKeys" args="key">
t1.reset1();
</handler>
</view>
<text id="output" width="200" fontsize="16">Data will appear here.</text>
</canvas>
Attributes
Name Usage Type (Tag) Type (JS) Default Category
context JS only setter
ondata Tag only script eventhandler
onerror Tag only script eventhandler
p Tag & JS expression LzDataNode setter
The LzDataNode that the datapointer is pointing to. Calling setAttribute on attribute calls LzDatapointer.setPointer.
rerunxpath Tag & JS boolean Boolean setter
If true, re-evaluate the XPath expression when the dataset is edited. Defaults to false.
xpath Tag & JS string String setter
Attributes inherited from Component
cloneManager, datapath, databind
Attributes inherited from Node
id, name, oninit, parent, subnodes
Methods
addNode()
LzDatapointer.addNode(name, text, attrs)
Adds a new child node below the current context Parameters Name Type Desc name String The name of the new node. text String The text of the new node. attrs Dictionary An object containing the name : value pairs of attributes for this node. Returns Type Desc LzDataElement the new node
addNodeFromPointer()
LzDatapointer.addNodeFromPointer(dp)
Duplicates the node that dp is pointing to, and appends it it to the node pointed to by this datapointer, making the added node the last on the list. Parameters Name Type Desc dp LzDatapointer A pointer to the node to add Returns Type Desc LzDatapointer A pointer to the new node
comparePointer()
LzDatapointer.comparePointer(ptr)
Determines whether this pointer is pointing to the same node as ptr. Parameters Name Type Desc ptr LzDatapointer The datapointer to compare to this one. Returns Type Desc Boolean True if the datapointers are pointing to the same node.
deleteNode()
LzDatapointer.deleteNode()
Removes the node pointed to by the datapointer. If rerunxpath is true and xpath has been set, it will be re-evaluated. Otherwise, if the deleted node has a following sibling, the pointer is repositioned at that sibling. Otherwise the pointer is set to null.
deleteNodeAttribute()
LzDatapointer.deleteNodeAttribute(name)
Removes the name attribute from the current node. Parameters Name Type Desc name String The name of the attribute to delete.
getDataset()
LzDatapointer.getDataset()
Returns a reference to the datapointer's dataset. Returns Type Desc LzDataset The datapointer's dataset
getNodeAttribute()
LzDatapointer.getNodeAttribute(name)
Returns the value of the current node's name attribute. Parameters Name Type Desc name String The attribute to retrieve. Returns Type Desc String The value of the attribute.
getNodeAttributes()
LzDatapointer.getNodeAttributes()
Returns the attributes of the node pointed to by the datapointer in an Object whose keys are the attribute names and whose values are the attribute values Returns Type Desc Object An Object which represents the keys and values of the node attributes
getNodeCount()
LzDatapointer.getNodeCount()
Counts the number of element nodes that are children of the node that the datapointer is pointing to. Returns Type Desc Integer The number of child nodes for the current node
getNodeName()
LzDatapointer.getNodeName()
Gets the name of the node that the datapointer is pointing to. Returns Type Desc String The name of the datapointer's node
getNodeText()
LzDatapointer.getNodeText()
Returns a string that represents a concatenation of the text nodes beneath the current element. getNodeText and getOtherNodeText are the only way to access non-element data nodes. Returns Type Desc String The text in the node pointed to by the datapointer.
isValid()
LzDatapointer.isValid()
Tests whether or not this datapointer is pointing to a valid node. Returns Type Desc Boolean True if the current node is valid.
selectChild()
LzDatapointer.selectChild(amnt)
Moves down the data hierarchy to the next child node in the dataset if possible. Parameters Name Type Desc amnt Number If given, the number of nodes to go down. If null, amnt is 1. Returns Type Desc Boolean True if the pointer was able to move down amnt nodes.
selectNext()
LzDatapointer.selectNext(amnt)
Selects the next sibling node in the dataset if possible. Parameters Name Type Desc amnt Number If given, the number of nodes to advance. If null, amnt is 1. Returns Type Desc Boolean True if the pointer was able to move forward amnt nodes.
selectParent()
LzDatapointer.selectParent(amnt)
Moves up the data hierarchy to the next parent node in the dataset if possible. Parameters Name Type Desc amnt Number If given, the number of nodes to go up. If null, amnt is 1. Returns Type Desc Boolean A Boolean indicating if the pointer was able to move up amnt nodes.
selectPrev()
LzDatapointer.selectPrev(amnt)
Selects the previous sibling node in the dataset if possible. Parameters Name Type Desc amnt Number If given, the number of nodes to move back. If null, amnt is 1. Returns Type Desc Boolean True if the pointer was able to move back amnt nodes.
serialize()
LzDatapointer.serialize()
Serialize the current element and its children to an XML string. Note that even if this datapointer's XPath ends in a terminal selector (such as @attribute or text()) this method will return the serialized text of the element that the datapointer points to. Returns Type Desc String A string of XML that represents all of the datapointer's contents.
setFromPointer()
LzDatapointer.setFromPointer(dp)
Sets this datapointer to the location of the given datapointer Parameters Name Type Desc dp LzDataPointer The datapointer which has the desired location for this datapointer.
setNodeAttribute()
LzDatapointer.setNodeAttribute(name, val)
Set the name attribute of the current node to the val. Parameters Name Type Desc name String The name of the attribute to set val String The value for the attribute
setNodeName()
LzDatapointer.setNodeName(name)
Sets the name of the current element to the name. Parameters Name Type Desc name String The new name for the datapointer's node
setNodeText()
LzDatapointer.setNodeText(val)
Sets the current node's text to value. When this node is serialized, the text will be represented as the first child node of this node. If the node already has one or more text children, the value of the first text node is set to the val. Parameters Name Type Desc val String The new string for the node's text
setPointer()
LzDatapointer.setPointer(p)
Points this datapointer at p. Parameters Name Type Desc p LzDataNode The new target for this datapointer.
setXPath()
LzDatapointer.setXPath(p)
Sets the xpath attribute to param, and sets the current node to the node that it refers to. If the XPath contains a terminal selector such as text(), the datapointer's data property is set to that value. It is error to set a datapointer to an XPath that matches multiple nodes. Parameters Name Type Desc p String An XPath. Returns Type Desc Boolean|Undefined true if the path matches a single node, false if no or multiple nodes are matched, undefined if the path is invalid.
Methods inherited from LzNode
animate, applyConstraint, applyData, childOf, completeInstantiation, construct, createChildren, dataBindAttribute, destroy, determinePlacement, getAttribute, getOption, getUID, init, lookupSourceLocator, searchImmediateSubnodes, searchSubnodes, setAttribute, setDatapath, setID, setName, setOption
Events
Name Description
ondata Sent when the data selected by this datapointer's xpath changes. For XPaths which select a datanode, this means that the datapointer is pointing to a new node. For XPaths which select text data, this means that the datapointer is pointing to a new node, or that the text selected by the xpath has changed. Note that a datapointer mapped to a data node will not receive
ondata when the node, say, changes one of its attributes.
onDocumentChange
onerror Sent when the dataset that the datapointer is pointing to generates an error.
onp
onrerunxpath
ontimeout Sent when a request by the dataset that the datapointer is pointing to times out.
Events inherited from LzNode
ondata, oninit

