⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resulttree.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
 * Isomorphic SmartClient
 * Version 6.5 (2008-04-30)
 * Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
 * "SmartClient" is a trademark of Isomorphic Software, Inc.
 *
 * licensing@smartclient.com
 *
 * http://smartclient.com/license
 */
//> @groupDef treeDataBinding// // The SmartClient +link{TreeGrid} component is a visual representation of a tree and requires// a +link{Tree} or +link{ResultTree} datatype passed via the +link{TreeGrid.data} attribute to// initialize the tree view.  The +link{Tree} datatype is used when you want to provide all of// the tree nodes in one shot at initialization time.  The +link{ResultTree} datatype is used// when you want portions of the tree to be loaded on demand from the server.// <p>// <b><u>Providing all data to the Tree at creation</u></b>// <p>// The simplest mechanism by which to initialize a Tree is to simply provide all the data// up-front when the Tree itself is created.  Depending on the format of your tree data, this// can be done by setting +link{Tree.root} or +link{Tree.data}.  This functionality is provided// by the +link{Tree} class.// <p>// For examples of this type of databinding, see the following SDK examples:// <ul>// <li>+externalLink{/examples/components/treeGrid_init.html, TreeGrid Initialization Example}// <li>+externalLink{/examples/server_integration/#jstlTree, TreeGrid Initialization with JSTL}// </ul>// <p>// <b><u>Loading Tree nodes on demand</u></b>// <p>// In this mode, tree nodes are loaded on-demand the first time a user expands a folder.  This// approach is necessary for large trees.  This functionality is provided by the// +link{ResultTree} class.// <p>// ResultTrees require that every node in the tree have an +link{Tree.idField,id} that is// unique tree-wide.  When the user expands a folder whose contents have not yet been loaded// from the server (or you programmatically call openFolder() on such a node), the client// automatically sends a +link{DSRequest} to the server to ask for all immediate children of// that node.  The +link{DSRequest} criteria will specify the id of the node for which children// are being requested via the <code>parentId</code> property (see +link{Tree.parentIdField}).// This client is asking the server: "give me all nodes whose parentId is the id of this// node".  // <P>// If there are no pre-existing node ids in the dataset you are loading, you must generate node// ids (because the client needs some way to identify nodes when talking to the server).// Generally a node id should contain whatever information is required to fetch the node and// it's children on the server.  One typical approach is to use the path to the node as a node// id.  For XML datasets in particular, the path may be a valid XPath, so that node lookup is// just applying an XPath to an XMLDocument.// <p>// +link{ResultTree}s are created for you by the +link{TreeGrid} when you set// +link{TreeGrid.dataSource}, but you can pass an initial dataset to a databound TreeGrid by// setting +link{TreeGrid.initialData}.  The +link{Tree.idField} is derived from the dataSource// you provide to the TreeGrid - the first field marked as// +link{DataSourceField.primaryKey}:true becomes the idField of the ResultTree.// The +link{Tree.parentIdField} is found by looking for a field that has a// +link{DataSourceField.foreignKey} property pointing to the idField.// <P>// If you do not provide +link{TreeGrid.initialData}, the first DSRequest you receive will be a// request for the nodes under root.  The id of the root node of the tree is the value of the// <code>rootValue</code> attribute on the +link{Tree.parentIdField} of the Tree DataSource. // <p>// For examples of this type of databinding, see the following SDK examples:// <ul>// <li>+externalLink{/examples/databinding/tree_databinding.jsp, TreeGrid DataBinding Example}// <li>+externalLink{/examples/server_integration/#xml2JSLOD, TreeGrid XML DataBinding}// </ul>// <P>// <b><u>Multi-Level load on demand</u></b>// <P>// Although the ResultTree's DSRequests ask for the immediate children of a node only, you are// free to return multiple levels of children.  This can be done by simply returning a flat// list of descendents with valid id's and parentId's, exactly as though you were initializing// a multi-level tree via +link{Tree.data}.  // <P>// Note that when receiving multiple levels of children, the ResultTree's assumption is that// if any children are loaded for a parent, then that parent is considered fully loaded.// <P>// When loading children for a given parent node, the ResultTree calls// +link{DataSource.fetchData} on its DataSource.  For custom code that may need to reference// the parentNode or tree in some way, the parent node whose children are being loaded is// available on the dsRequest instance in the DataSource flow as dsRequest.parentNode, where it// can be inspected during +link{DataSource.transformRequest()}.//// @title Tree DataBinding// @treeLocation Client Reference/Data Binding// @visibility external//< //>	@class ResultTree////  ResultTrees are an implementation of the +link{class:Tree} API, used to handle hierarchical//  data, whose nodes are DataSource records which are retrieved from a server.// @visibility external// @treeLocation    Client Reference/Data Binding//<isc.ClassFactory.defineClass("ResultTree", isc.Tree);isc.ResultTree.addProperties({    nameProperty:"__nodePath",    nodeTypeProperty:"nodeType",    childTypeProperty:"childType",    modelType: "parent",    // DataModel	// ---------------------------------------------------------------------------------------    //> @attr resultTree.dataSource (DataSource or ID : null : IR)    //  What +link{class:DataSource} is this resultTree associated with?    //    // @include dataModel.dataSource    // @visibility external    //<    //> @attr resultTree.context (OperationContext : null : IRA)    // OperationContext to be sent with all operations performed by this ResultTree.    //<    //> @attr   resultTree.loadDataOnDemand (boolean : true : IR)    // Does this resultTree load data incrementally as folders within the tree are opened, or    // is it all loaded in a single request?    // @see treeGrid.loadDataOnDemand    // @visibility external    //<    loadDataOnDemand:true,    //> @attr resultTree.defaultIsFolder (boolean : null : IR)    // Controls whether nodes are assumed to be folders or leaves by default.    // <P>    // Nodes that have children or have the +link{isFolderProperty} set to true will always be    // considered folders.  Other nodes will be considered folders or leaves by default according    // to this setting.    // <P>    // If <code>defaultIsFolder</code> is unset, the ResultTree will automatically set it to    // match the value of +link{loadDataOnDemand}.  This means that, when using    // folder-by-folder load on demand (<code>loadDataOnDemand:true</code>), by default a newly    // loaded node will be considered to be a folder that has not loaded its children yet.      // <P>    // When not using folder-by-folder load on demand, by default a newly loaded node is    // considered a leaf.  If you set <code>defaultIsFolder:true</code> explicitly, by default    // a newly loaded node is considered to be a folder with no children.    // <P>     // See +link{Tree.isFolder()} for details on how to explicitly mark nodes as folders or leaves.    //    // @see treeGrid.loadDataOnDemand    // @visibility external    //<    //> @attr resultTree.updateCacheFromRequest (boolean : true : IRA)     // When a successful Add, Update or Remove type operation fires on this ResultTree's     // dataSource, if +link{dsResponse.data} is unset, should we integrate the submitted    // data values (from the request) into our data-set?    //    // @group cacheSync    // @visibility external    //<    updateCacheFromRequest:true        //> @attr   resultTree.disableCacheSync (boolean : false : IRA)    // By default when the data of this ResultSet's dataSource is modified, the ResultSet will    // be updated to display these changes.    // Set this flag to true to disable this behavior.    // @group cacheSync    // @visibility external    //<});isc.ResultTree.addMethods({//>	@method	resultTree.init()	(A)//			Initialize this ResultTree.  Pass in objects with properties to add or override//			defaults.////		@param	[all arguments]	(object)	objects with properties to override from default//<init : function (a,b,c,d,e,f) {    if (this.initialData) {        if ("parent" == this.modelType) this.data = this.initialData;        else if ("children" == this.modelType) this.root = this.initialData;    }	if (!this.criteria) this.criteria = {};    if (!this.operation) this.operation = {operationType : "fetch"};    // dataSource can be specified either on the operation or the ResultTree.    if (!this.dataSource) this.dataSource = this.operation.dataSource;    if (!this.operation.dataSource) this.operation.dataSource = this.dataSource;            if (isc.isAn.Array(this.dataSource)) {        this.dataSource = this.dataSource[0];        this.operation.dataSource = this.dataSource;    }        // observe dataChanged on our dataSource    var dataSource = isc.DataSource.getDataSource(this.dataSource);    this.observe(dataSource, "dataChanged", "observer.dataSourceDataChanged(dsRequest,dsResponse);");            // If any of rootValue, idField, parentIdField are not explicitly specified on this    // ResultTree, autodetect them from the DataSource relationship.    if (!this.isMultiDSTree()) {        // root node has to exist for getTreeRelationship to work, so create it now if it        // doesn't exist         if (!this.root) this.root = this.makeRoot();        var relationship = this.getTreeRelationship(this.root);        var undef;        // compare to undef because rootValue can be set to null        if (this.rootValue === undef) this.rootValue = relationship.rootValue;        if (this.idField == null) this.idField = relationship.idField;        if (this.parentIdField == null) this.parentIdField = relationship.parentIdField;        if (relationship.childrenProperty) this.childrenProperty = relationship.childrenProperty;                this.root[this.idField] = this.rootValue;    }    // whether to invalidate our cache when an update occurs on one of our datasources.    // Default is update the current cache in place.    this.dropCacheOnUpdate = this.operation.dropCacheOnUpdate;    this.invokeSuper(isc.ResultTree, "init", a,b,c,d,e,f);        // if we're not using folder-by-folder load on demand, all nodes should be initially marked loaded    this.defaultLoadState = this.loadDataOnDemand ? isc.Tree.UNLOADED : isc.Tree.LOADED;    if (this.defaultIsFolder == null) this.defaultIsFolder = this.loadDataOnDemand;},destroy : function () {    this.Super("destroy", arguments);    var dataSource = isc.DataSource.getDataSource(this.dataSource);    if (dataSource) this.ignore(dataSource, "dataChanged");},// A Tree navigates a 1 to many (parent to children) relationship, which can exist within or // across DataSources.// figuring out the type of child records at each level of the tree// - use cases//   - all one type//     - supported: set just this.dataSource//   - fixed levels//     - example: salesOrder, lineItem//     - supported: set this.dataSource for root DataSource, this.treeRelations for transitions//   - mixed child types (each parent in a level has different child types)//     - example: outlook left-hand tree navigation: top level is a random conglomeration of Inbox,//       Favorites, etc, each with different child node types (message folders, filesystem folders,//       etc)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -