Database dynamically generated tree directory

zhaozj2021-02-16  28

I. Wide application of catalog trees

For this content, search for Search on Baidu, the content is a big pass, the relevant actually doesn't. Search? Is it not a clear use? The management of the resource manager folder, the management of multi-level forums in the forum, the AWT in Java is the lack of components such as the tree directory are limited ... Who is so rude, no face is not given? , How do I talk about? Clear clear:

In our project, the self-associated data table often occurs, from the overall look, the entire table is presented as a tree data structure. When we display this table, when we do not adopt a good expression, it will be very awkward, and the tree directory is obviously a good idea.

(The ax is a circle, I feel good, then talk ...) In the tree directory in the web, the tree directory can be implemented with JavaScript, but some details are issued, such as tree directory (click on a child node, open the associated link) , Multi-level catalogs and nodes increase, delete, and drag are subject to various elbows. In fact, the third-party control is obviously a good idea. Second, about Zhi Island directory tree control

Ok, our protagonist today - a lightweight honest catalog tree control (download address: http://www.oapro.com/ostarocx/download/otree.ocx) appeared. It uses VC 6.0 development, which is a standard OCX control, which can be applied to the programming language such as VB, VC, PB, DEPHI, ASP, JSP, etc. in a Windows environment. It uses an XML file as an interface file, which can be an off-the-shelf file or a dynamically generated XML format file (in other words can be based on the database dynamically generated directory tree node). Pisd Island directory tree control supports the replication, movement, renaming, and permission controls of nodes, and does not limit the number of layers of the directory. Introduced so much, I want to try it. In the ASP, small test cattle knife first:

Third, registration add control

Registered Zhi Island directory tree control

Download (Download Address: http://www.oapro.com/ostarocx/download/otree.ocx) After the That Otree.ocx is Otree.ocx, register the control as follows: Click "Start" → "Run"; enter the following command in the Run dialog: Regsvr32 Register Zi Island directory tree control control Regsvr32 / u Release the Zhi Island directory tree control

2. Add a Zhimam directory tree control in the page

Add the following code to the page, you can insert the Zi Island directory tree control: where: width and height: refer to the display width and height of the control; ID: The name of the control object, through the name Name implements the operation of the control; CodeBase: Refers to the address that is automatically downloaded to install the control when the client does not install the Pin Island directory tree control. Third, generate tree directory from XML file

XML document format

XML is a good stuff, but it is also necessary to meet a certain format, otherwise the control can not be recognized! Here is a XML document format:

| Development Department | ... where: nodename: Refers to the node name, if there is a superior node, include the superior node name, the node name Symbol "/" separated. Example "My Office / Announcement Notification / Email" indicates that the root node is "My Office", the parent node is "Announcement Notice", this node is "email". If you ask you how to include the five-level node name, huh, don't throw me with tomatoes! NodeType: Node type, generally refers to "href". ImageIndex: The small icon appears before the node name, where 0 indicates that the folder icon, 4 indicates the data species icon.

Below is an XML format document source code: My office desk href mydesk.aps 0 0 My Office desk / announcement notification HREF Announcement Notice .aps 0 0 My Office desk / Announcement Notification / Email 0 My Office / Announcement Notification / Email / Inbox 4 < NodeItem> My Office / Announcement / Email / Outbox 4 My desk / announcement notification / email / email My work desk / schedule 0 My Office desk / schedule / calendar 2. Code implementation

Inform the Zi Island directory tree control through the following statement: Otree.OpenXMLFile (") in the quotient path of the XML document, for example: Otree.OpenXMLFile (" c: /otree.xml ") is shown in the following image: I have seen you frequently nod, but I murmire: If you want to generate a tree directory according to the content of the database ...? Oh, let's go to the topic (the text in front of dare to be a lot of words? Who is ? Hey ..., small voice point, don't let Xiaobian see): Fourth, Based on Database Generation Stroke Directory

XML document format

Put the node of the tree directory into the database and dynamically form a good foundation for our tree directory. Of course, some directory trees are data structures in a database (the parent node is the database name, the child node is a data sheet). Anyway, with the previous foundation, now we need to do just to form the contents of the database above the XML document. There is an ASP source code below to form an XML document in the database, where the variable DataSource stores the passed database name.

<% DIM Datasource DataSource = Request ("Datasource")%> <% = Datasource%> 0 | Development Department | Marketing | 0 <% strconn = "dbq =" server.mappath ("DB /" & Datasource) "; defaultdir =; driver = {Microsoft Access Driver (* .mdb)};" set objconn = server. createobject ( "Adodb.connection") objConn.open strConn set rsSchema = objConn.openSchema (20) rsSchema.movefirst Do Until rsSchema.EOF if rsSchema ( "TABLE_TYPE") = "TABLE" then%> < % = Datasource%> / <% = rsSchema ("Table_name")%> href <% = rsschema ("Table_name")%> 4 | Development Department | Marketing | 0 <% end if rsschema.movenext loop set objconn = NOTHING%> 2. Code implementation

At this time, the interface method is different from the XML document directly: Otree. Httpget ("http://www.oapro.com/ostarocx/sample/dataman/otree.asp", "Datasource = Otree. MDB ")] The method httpget has two parameters. The first parameter is the web page address of the implementation database conversion XML format described above. Be sure to use the relative or absolute path (because the method is not yet supported by the current method" ), The second parameter is the parameter passed to the file, where we passed the database name. According to the above introduction, you quickly realize a tree directory, point the root node, expand, parent node, expand, then click ..., 咦, how can you not respond? What react do you want? Oh, I am sorry, I almost forgot to introduce: V. Response node event

Zhi Island Tree Catalog Control provides an interface method to respond to node events: eventtree, stritemdata, stritemTyMName, StriteMName Name StriteMData Node Data StriteMType Node Type These three parameters are provided by the Zhi Island tree directory control. Developers for us to call. We can trigger events through scripts, the following is an example code: