com.judah.controls.dataproviders
class RecordsetToXML
Object
|
+--com.judah.controls.dataproviders.RecordsetToXML
class RecordsetToXML extends Object
Recordset to XML tree class
This class is used to convert a recordset into an xml tree
- Usage:RecordsetToXML.parse()
- Author:Judah Frangipane
- Example:This example takes a recordset from Flash remoting and organizes it into a xml tree structure for the Tree component. You can also use it to take a List or DataGrid component and convert it into an xml list. If you want to output a different xml structure then modify the convertToNode function. You can change the node name and root node name in the xml by changing the associated nodeName and rootNodeName properties. See the parse function for more documentation.
// A item in this recordset have these properties // Label:String = "Cameras" // ParentID:Number = 2 // Order:Number = 1 // ID:Number = 1 import com.judah.controls.dataproviders.RecordsetToXML; // setup services... myService.getCatalogs(); // service calls successful results function function getCatalogs_Result(result){ // create custom root node var myTreeRoot = new XML(); myTreeRoot.addTreeNode("Product Catalog", 0); myTreeRoot = myTreeRoot.firstChild; myTree.dataProvider = RecordsetToXML.parse(result.items,"ID","ParentID","Label", myTreeRoot, true, true); // you could pass in 0 in the "ParentID" field if the recordset does not have a parent id //myTree.dataProvider = RecordsetToXML.parse(result.items,"ID",0,"Label", myTreeRoot, true, true); // if you want to output a different xml structure then modify the convertToNode function }
Method Summary
public static convertToNode (
theItem, newNode, labelField, createLabelAttribute
)
A user customizable function to convert the row item into a node
public static parse (
recordset, idField: String, parentIdField: String, labelField: String, theRootNode, placeOnRoot: Boolean, createLabelAttribute: Boolean
)
Parses the recordset into an xml dom
Field Documentation
nodeName
public static var nodeName: String
A user customizable node name
A user customizable node name. By default each node name is "node".
rootNodeName
public static var rootNodeName: String
A user customizable root node name
A user customizable root node name. By default the root node name is "nodes".
Method Documentation
convertToNode
public static function convertToNode (
theItem,
newNode,
labelField,
createLabelAttribute)
newNode,
labelField,
createLabelAttribute)
A user customizable function to convert the row item into a node
A user customizable function to convert the row item into a node
- Parameters:
theItem Object - The row item that will be converted into a node newNode Object - The node that will be created from the row item labelField String - Field in the database or property in the item that should be used as the labelField as defined in the tree createLabelAttribute Boolean - Takes the value of the labelField defined in the item and copies that value into the "label" attribute. Default value is false. Optional
parse
public static function parse (
recordset,
idField: String,
parentIdField: String,
labelField: String,
theRootNode,
placeOnRoot: Boolean,
createLabelAttribute: Boolean)
idField: String,
parentIdField: String,
labelField: String,
theRootNode,
placeOnRoot: Boolean,
createLabelAttribute: Boolean)
Parses the recordset into an xml dom
Parses the recordset into an xml dom
- Parameters:
recordset Object - Recordset or resultset items property usually from a remoting call idField String - Id field of the record. Corresponds directly with the parentIdField parentIdField String - Id of the record that is the parent of this record. Zero or undefined if the record is on the root. Corresponds directly with the idField. Pass in undefined, 0 or a field that does not exist if there are no parent ids in your recordset. labelField String - Field in the database that should be used as the labelField as defined in the tree theRootNode String - Text or XMLNode object to be used for the root node. The placeOnRoot property must be false to see this node in the tree view. Optional placeOnRoot Boolean - Defines if the records with no parent are directly on the root of the tree or if they are underneath a visible root node. Default value is false. Optional createLabelAttribute Boolean - Takes field in the database defined as the labelField and copies that value into the "label" attribute. Default value is false. Optional - Returns:Object - Returns an xml object ready to assign to the tree dataprovider
- Usage:myTree.dataProvider = RecordsetToXML.parse(recordset.items,"id field","parent id field","tree label field", xmlRootNode, bPlaceOnRoot, bCreateStandardTreeLabel);
- Example:This code parses a recordset from a getCatalogs service call and places it into a tree.
// A item in this recordset have these properties // Label:String = "Cameras" // ParentID:Number = 2 // Order:Number = 1 // ID:Number = 1 import com.judah.controls.dataproviders.RecordsetToXML; // setup services... myService.getCatalogs(); // service calls successful results function function getCatalogs_Result(result){ // create custom root node var myTreeRoot = new XML(); myTreeRoot.addTreeNode("Product Catalog", 0); myTreeRoot = myTreeRoot.firstChild; myTree.dataProvider = RecordsetToXML.parse(result.items,"ID","ParentID","Label", myTreeRoot, true, true); // you could pass in 0 in the "ParentID" field if the recordset does not have a parent id //myTree.dataProvider = RecordsetToXML.parse(result.items,"ID",0,"Label", myTreeRoot, true, true); // if you want to output a different xml structure then modify the convertToNode function }
- RecordsetToXML.as, Last Modified: 6/3/2006 1:48:14 AM