Dataset(LzDataset)
出自OpenFace
<dataset>
An in-memory xml-style data hierarchy. JavaScript: LzDataset
Extends LzDataElement
A <dataset> tag defines a local dataset. The name of the dataset is used in the datapath attribute of a view.
The src attribute of the <dataset> element specifies whether the data is compiled into the application or fetched at runtime:
- If the src attribute is a URL, the value of the dataset is the XML data that a request to the URL named by the src attribute returns when the application is run.
- If the src attribute is a pathname, the value of the dataset is the content of the XML file that the pathname refers to, and is compiled into the application.
- If the src attribute is not present, the value of the dataset is the content of the <dataset> element.
All data in an OpenLazlo application is contained within one or more datasets. A given dataset usually represents a single conceptual set that may or may not be modified or reloaded during the execution of the application. The data within a dataset is accessed using a <datapointer> or a instance of one of its subclasses. Datasets can represent
- local data (i.e. data which is static after compile time), or
- http-data (data which is returned as XML over HTTP)
If a dataset is not explictly contained within in a datasource, it will make an instance of datasource and be contained inside that. A dataset can be populated or re-poplulated at runtime by calling doRequest on the dataset. The result of the request is then returned to the application and the dataset's ondata event is run. Any datapointer that is bound to the dataset will also run its ondata event at this time as well.
See the Developers's Guide for more discussion of data and datasets.
The example below makes a request of the cgi script on Laszlo's website that serves up weather information in xml form. Example 1. Making a request using a dataset
<canvas height="250" width="800"> <dataset name="myData" src="http://localhost:8088/OpenLaszlo/test/text.xml" type="http" request="false" > </dataset> <handler name="oninit"> alert("@@@@@@@@@@222oninit"); canvas.myData.doRequest(); </handler> <text x="10" y="100" fontsize="16" datapath="myData:/myXML[1]/person[1]/firstName[1]/text()" /> <text x="10" y="130" fontsize="16" datapath="myData:/myXML[1]/person[2]/lastName[1]/text()" /> </canvas>
Attributes
Name Usage Type (Tag) Type (JS) Default Category
cache Tag & JS boolean Boolean false readonly
When true, the server will attempt to cache response (defaults to false). There are security concerns when this field is true. When this field is true, you will usually want the getresponseheaders field to be false.
life Tag & JS string String false readonly
Set the lifetime of data cache.format:"days, hours, minutes"
ondata Tag only script LzEvent eventhandler
Sent when new data arrives for this dataset
onerror Tag only script LzEvent eventhandler Sent when an error occurs for this dataset
querytype Tag & JS get | post | GET | POST any setter
HTTP request method = post | get
request Tag & JS boolean Boolean setter
If true, the datset will make a request when it inits. The default for this is false.
src Tag & JS String setter
The source for requests made by this dataset.
trimwhitespace Tag & JS boolean Boolean false readonly
When true, the server will trim whitespace in the XML data (defaults to false).
type Tag & JS string String setter
If set to "http", then the dataset will interpret its src attribute as an url from which to load its content, rather than as a static xml file to inline.
Attributes inherited from LzDataElement
attributes, childNodes, nodeName, ownerDocument
Attributes inherited from LzDataNode
nodeType, parentNode
Attributes inherited from Node
id, name, parent, subnodes
Methods
abort()
LzDataset.abort()
Stops the load of the dataset's current request
refreshData()
LzDataset.refreshData()
Forces the system to fetch remote data directly and use it to refresh the local cache.
doRequest()
LzDataset.doRequest()
Does a request immediately using the current values. If autorequest is true, this method is called automatically when values change.
getParams()
LzDataset.getParams()
Returns an LzParams object holding any set request parameters for the dataset. Returns Type Desc LzParam The request parameters for the dataset.
getPointer()
LzDataset.getPointer()
Returns a datapointer pointing to the root of the dataset. Returns Type Desc LzDatapointer A datapointer that points to the root of the dataset.
getQueryString()
LzDataset.getQueryString()
Returns the querystring attribute of the dataset, if there is one Returns Type Desc String The querystring attribute of the dataset
getSrc()
LzDataset.getSrc()
Return the src attribute of the dataset, if one was given. Returns Type Desc String The src of attribute of the dataset
setQueryParam()
LzDataset.setQueryParam(key, val)
Sets a named query parameter to the given value. The query parameters are sent with every request. The key 'lzpostbody' has a specific interpretation, see setQueryType() for details. Parameters Name Type Desc key String The name of the parameter val String The value for the parameter
setQueryParams()
LzDataset.setQueryParams(o)
Sets multiple query parameters from using the keys in the argument as keys and the values of those keys as values. This method can also be used to clear the query params, by passing null to it. Parameters Name Type Desc o Object An object whose keys are keys of parameters and whose values are those parameters' values. Passing a value of null to this method clears the query parameters. The key 'lzpostbody' has a specific interpretation, see setQueryType() for details.
setQueryString()
LzDataset.setQueryString(s)
Sets the querystring parameter of the dataset of the dataset to the given string. The dataset's querystring will be pre-pended to any request made for the dataset. Parameters Name Type Desc s String A string to be appended to any query made on behalf of this datset
setQueryType()
LzDataset.setQueryType(reqtype)
Sets the query type of for the datasource to one of "POST" or "GET" by calling the method of the same name on this dataset's datasource. Note that this controls how the LPS server makes a request of the backend, as well as how the client communicates with the LPS Parameters Name Type Desc reqtype Sring A string -- either "GET" or "POST". GET is the default. When the type is "POST", the query parameters will be sent in the request body, encoded as application/x-www-form-urlencoded If the type is "POST" and there is a exactly one request parameter and it is named "lzpostbody", it will be used as the raw request body (unencoded). Use of "lzpostbody" with a request that has more than one request parameter is undefined.
setRequest()
LzDataset.setRequest(b)
Sets whether or not the dataset makes its request upon initialization Parameters Name Type Desc b Boolean If true, the dataset will make its request when it is initialized
setSrc()
LzDataset.setSrc(src)
Sets the src attribute of the dataset's datasource. Parameters Name Type Desc src String A new src for the dataset's datasource.
Methods inherited from LzDataElement
appendChild, cloneNode, constructor, getAttr, getElementsByTagName, getFirstChild, getLastChild, getOffset, handleDocumentChange, hasAttr, hasChildNodes, insertBefore, makeNodeList, removeAttr, removeChild, replaceChild, serialize, setAttr, setAttrs, setChildNodes, setNodeName, valueToElement
Methods inherited from LzDataNode
childOf, getNextSibling, getPreviousSibling, setOwnerDocument, stringToLzData
Methods inherited from LzNode
childOf, createChildren,destroy,getAttribute,init, setAttribute,setName
Events
Name Description
onerror None

