先看代码:

var TreeForJSON = new dhtmlXTreeObject('TreeForJSON', '100%', '100%', 0);
TreeForJSON.setImagePath("dhtmlx/codebase/imgs/csh_vista/");
TreeForJSON.enableDragAndDrop(true);
TreeForJSON.enableKeyboardNavigation(true)
TreeForJSON.loadJSONObject({id:0,
item:[
{id:1,text:"first",userdata:[{name:'url',content:'http://g.cn#1'}]},
{id:2, text:"middle",userdata:[{name:'url',content:'http://g.cn#2'}],
item:[
{id:"21", text:"child",userdata:[{name:'url',content:'http://g.cn#3'}]}
]},
{id:3,text:"last",userdata:[{name:'url',content:'空'}]}
]
}
);
TreeForJSON.setOnClickHandler(TestOnClick);
function TestOnClick(id){
var url = (TreeForJSON.getUserData(id, "url"));
alert(url);
}

dhtmlxTree中的loadJSONObject方法也是支持userdata属性的,只是写法特殊一点
取值时是通过当前ID去找userdatea下的name,如代码中的url,然后获取其content内容,即http://g.cn...
同理,使用这个方法可以自定义更多的属性

userdata:[{name:'type',content:'1'},{name:'remark',content:'空'}]

dhtmlXTree API

Methods
assignKeys configures the keys used for keyboard navigation
attachEvent adds any user-defined handler to available events
changeItemId changes the item's id
clearCut cancels marking an item as cut
clearSelection unselects the item in the tree
closeAllItems collapses target node and all sub nodes
closeItem collapses a node
deleteChildItems deletes all children of the node
deleteItem deletes a node
destructor deletes tree and clears memory
detachEvent detaches a handler from an event
disableCheckbox disables a checkbox
doCut marks the selected item as cut
doPaste inserts the previously cut branch
editItem opens editor for the specified item
enableActiveImages enables active images (clickable and dragable). By default only text part of the node is active
enableAutoSavingSelected enables/disables autosaving selected node in cookies
enableAutoTooltips enables auto tooltips (node text as tooltip)
enableCheckBoxes shows/hides checkboxes (all checkboxes in the tree)
enableContextMenu enables context menu
enableDistributedParsing enables distributed parsing of a big tree (items loaded portion by portion with some timeouts)
enableDragAndDrop enables/disables drag-and-drop
enableDragAndDropScrolling enables/disables auto scrolling during the drag-and-drop operation
enableHighlighting enables item highlighting (item's text is highlighted on mouseover)
enableIEImageFix replaces IMG tag with background images - solves the problem with IE image caching, doesn't work for IE6 SP1
enableImageDrag enables dragging an item by its image (by default an item is dragged by text)
enableItemEditor enables editing of the item's text
enableKeySearch enables searching of items by pressing keys
enableKeyboardNavigation enables keyboard navigation in the tree
enableLoadingItem enables/disables "Loading..." item
enableMercyDrag enables dragging without removing (copies instead of moving)
enableMultiLineItems enables multiline items
enableMultiselection enables multiselection
enableRTL enables Right-to-Left mode in the tree
enableRadioButtons replaces checkboxes with radio buttons
enableSingleRadioMode replaces checkboxes with radio buttons
enableSmartCheckboxes enables smart checkboxes
enableSmartRendering enables smart rendering mode
enableSmartXMLParsing enables/disables smart XML parsing mode
enableTextSigns replaces images with text signs
enableThreeStateCheckboxes enables three-state checkboxes
enableTreeImages enables tree images
enableTreeLines enables/disables tree lines (parent-child threads)
findItem finds a tree item by text, selects it and focuses on it
findItemIdByLabel finds a tree item by text
focusItem scrolls Tree to the indicated item to make it visible and sets focus on it
getAllChecked returns the list of ids of the nodes with checked checkboxes, separated by default delimiter
getAllCheckedBranches returns the list of ids of the nodes with checked and three-state checkboxes, separated by default delimiter
getAllChildless returns the list of all items which don't have child nodes
getAllItemsWithKids returns the list of all items which have child nodes, separated by default delimiter
getAllPartiallyChecked returns the list of ids of the nodes with three-state checkboxes, separated by default delimiter
getAllSubItems returns the list of all children nested on all sublevels of the tree (in relation to the specified item)
getAllUnchecked returns the list of identificators of the nodes with unchecked checkboxes, separated by default delimiter
getAttribute returns the value of the specified item attribute
getChildItemIdByIndex returns child node's id by index
getDistributedParsingState gets the current state of distributed parsing
getIndexById returns the node's index in the children collection by id
getItemColor gets the color of the target item
getItemIdByIndex returns the node's id by index
getItemImage gets URL of the item's image
getItemParsingState gets current parsing state of an item
getItemText returns the node's text
getItemTooltip gets item's tooltip
getLevel gets the node's level (position in the hierarchy)
getOpenState returns open/close state
getParentId returns the parent item's id
getSelectedItemId returns the selected item's id
getSelectedItemText returns the selected node's text
getSubItems returns a comma-delimited list of ids of all children nested on the sublevel in relation to the specified item
getUserData gets user data from the target node
getXMLState returns the current state of XML loading
hasChildren returns the number of children
insertNewChild creates a new node as a child to the specified one with parentId
insertNewItem creates a new node as a child to the specified one with parentId
insertNewNext creates a new node next to the specified one
isItemChecked gets the state of the node's checkbox
isLocked returns "true" if the item is locked
load loads data to the component via XML or JSON, usually data-values pairs
loadCSV loads tree from csv file/stream
loadCSVString loads tree from csv string
loadJSArray loads tree from js array object
loadJSArrayFile loads tree from js array file/stream
loadJSON loads tree from json file
loadJSONObject loads dhtmlxTree from a JSON object
loadOpenStates restores open nodes from cookie
loadState loads tree from cookie
loadXML loads tree from xml file
loadXMLString loads tree from xml string
lockItem locks/unlocks an item
lockTree locks tree
makeAllDraggable adds drag-n-drop capabilities to all HTML items with dragInDhtmlXTree attribute
makeDraggable adds drag-n-drop capabilities (with the possibility to drop into dhtmlxTree) to HTML object
moveItem moves an item (inside of tree)
openAllItems expands target node and all sub-nodes
openAllItemsDynamic expands target node and all child nodes (the same as openAllItems, but works in dynamic trees)
openItem expands a node
openItemsDynamic expands the list of nodes in dynamic tree (wait till the end of a node's loading before expanding the next one)
openOnItemAdded configures if parent node will be expanded immediately after a child item has been added
parse loads data from a local datasource (XML string, CSV string, XML island, XML object, JSON object, javascript array)
preventIECaching prevents caching in IE by adding a random value to URL string
refreshItem refreshes a tree branch from XML
refreshItems refreshes the specified tree nodes (gets XML from server and updates only the nodes included into itemIdList)
registerXMLEntity registers XML entity for replacement during the initialization (the default entities are: ampersand, less-than and greater-than symbols)
restoreSelectedItem restores the selected item from cookie
saveOpenStates saves open nodes to cookie
saveSelectedItem saves the selected item to cookie
saveState saves tree to cookie
selectItem selects the specified node (and optionally fires the onClick event)
serializeTree gets xml representation (as string) of tree
serializeTreeToJSON returns tree as json string
setAttribute sets an attribute for an item
setCheck sets the state of a node's checkbox
setChildCalcHTML sets children calculation prefix and postfix
setChildCalcMode sets children calculation mode
setCustomSortFunction sets custom sort function which has two parameters - id_of_item1,id_of_item2
setDataMode sets a default data transfer mode
setDragBehavior sets Drag-And-Drop behavior (child - drop as child, sibling - drop as sibling, complex - complex drop behaviour)
setEditStartAction defines which events must start the process of editing
setEscapingMode sets escaping mode (used for escaping ID in requests)
setIconSize sets the size of icons
setIconsPath defines path to the icons folder
setImageArrays sets the images used for parent-child threads drawing (lines, plus, minus)
setImagesPath defines path to the imgs folder
setItemCloseable prevents a node from closing
setItemColor sets the color of the node's text
setItemContextMenu sets context menu for individual nodes
setItemImage sets item's icons (mostly useful for childless nodes)
setItemStyle sets an individual item's style
setItemText sets a new node's text (HTML is allowed)
setItemTopOffset sets the top offset for an item
setListDelimeter sets list separator ("," by default)
setLockedIcons sets an icon for locked items
setSerializationLevel configures XML serialization
setSkin set skin for the component
setStdImages sets default images for nodes (must be called before XML loading)
setSubChecked changes the state of the node's checkbox and all children checkboxes
setUserData sets user data for the target node
setXMLAutoLoading enables dynamic loading from XML
setXMLAutoLoadingBehaviour defines the mode of passing to the server the id of an item for which the data should be loaded during dynamic loading
showItemCheckbox shows/hides a checkbox for a tree item
showItemSign shows/hides (+/-) an icon
smartRefreshBranch refreshes the specified tree branch (gets XML from server, adds new nodes, removes unused nodes)
smartRefreshItem refreshes the specified tree item (gets XML from server, adds new nodes, removes unused nodes)
sortTree reorders items in the tree according to their text
stopEdit switches the item which is currently being edited back to normal view
updateItem updates item's properties
Events
onAllOpenDynamic fires when all sub levels is loaded and opened
onBeforeCheck fires before an item is checked/unchecked
onBeforeContextMenu fires before the moment when a context menu appears on the right mouse click
onBeforeDrag fires when the item's dragging starts (the item is selected and the mouse is moving)
onCheck fires immediately after an item in the tree has been checked/unchecked
onClick fires when the text part of a tree item is clicked, but after the default onClick functionality has been processed
onDblClick fires right after a tree item has been double clicked, but before the default onDblClick functionality has been processed
onDrag fires when the item was dragged and dropped on some other item, but before item's moving has been processed
onDragIn fires when the item is dragged over some target the item can be dropped to
onDrop fires when drag-and-drop has already been processed; besides, fires when the nodes are moved programmatically
onEdit fires on 4 different stages of the editing process (see the details)
onEditCancel event occurs after cancelling edit by Escape key or other means
onKeyPress fires after each key press when tree is in focus
onMouseIn fires when the mouse pointer is hovered over an item
onMouseOut fires when the mouse pointer is moved out of item's area
onOpenDynamicEnd fires after the item defined in the openItemsDynamic() method opens
onOpenEnd fires right after an item in the tree has become open
onOpenStart fires right when an item in the tree starts to open, but before this item has opened
onRightClick fires when the user clicks the right mouse button
onSelect fires when selection in the tree was changed
onXLE fires when the data loading is finished and a component or data is rendered
onXLS fires when XML loading started

dhtmlxtree 如何得到xml,json等文件中的自定义的属性值的更多相关文章

  1. 在CSV文件中增加一列属性值

    具体参见:系统管理\将文件夹复制到列表中的远程主机   修改前: column1, column2 1,b 2,c 3,5   修改后: column1, column2, column3 1,b, ...

  2. Spring boot中普通工具类不能使用@Value注入yml文件中的自定义参数的问题

    在写一个工具类的时候,因为要用到yml中的自定义参数,使用@Value发现值不能正常注入,都显示为null: yml文件中的自定义格式 调用工具类的时候不能new的方式 要使用@Autowired的方 ...

  3. js中获取css样式属性值

    关于js中style,currentStyle和getComputedStyle几个注意的地方 (1)用js的style只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的.针对css ...

  4. JSON字符串反序列化成对象_部分属性值反序列化失败

    简介:本人在开发webapi接口时遇到了:一个复杂的Json字符串在反序列化为对象时报,无法发序列化其中的一个属性对象? 使用方法: InternalRecommendRequestFormModel ...

  5. MVC过滤器中获取实体类属性值

    本文地址:http://www.cnblogs.com/outtamyhead/p/3616913.html,转载请保留本地址! 最近在项目遇到了这个问题:获取Action行参中实体类的属性值,主要的 ...

  6. How to: Calculate a Property Value Based on Values from a Detail Collection 如何:基于详细信息集合中的值计算属性值

    This topic describes how to implement a business class, so that one of its properties is calculated ...

  7. 使用json读写文件中的数据

    把json的数据写入到文件中 import json with open('data.json','w+') as f: json.dump({"name":"张彪&qu ...

  8. castle windsor学习----- Referencing types in XML 在xm文件中引用类型

    当从xml引用installer的语法如下 <install type="Acme.Crm.Infrastructure.ServicesInstaller, Acme.Crm.Inf ...

  9. 微信小程序wxml文件中调用自定义函数

    想在微信小程序的wxml文件里自如的像vue那样调用自定义的方法,发现并不成功,得利用WXS脚本语言. WXS脚本语言是 WeiXin Script 脚本语言的简称,是JavaScript.JSON. ...

随机推荐

  1. python 全栈开发,Day7(元组转换,列表以及字典的坑,集合,关系测试,深浅copy,编码补充)

    一.元组转换 数字 tu = (1) tu1 = (1,) print(tu,type(tu)) print(tu1,type(tu1)) 执行输出: 1 <class 'int'>(1, ...

  2. For each loop in Native C++

    今天发现 for each 语法居然可以直接编译通过,之前还以为只有开了/clr才可以支持.查了一下资料发现ms从vs2005就已经支持了.虽然不符合标准不过用着确实方便啊,必须记录一下. 具体看这里 ...

  3. WCF客户端从服务器下载数据

    1.打开VS选择控制台项目新建一个解决方案Server,然后添加两个类库Contract和Service. 2.在Contract中添加一个接口IFileDownload using System; ...

  4. Linux中查找当前目录下占用空间最大的前10个文件

    du命令 计算出单个文件或者文件夹的磁盘空间占用 -a或--all:包含全部的文件系统: --block-size=<区块大小>:以指定的区块大小来显示区块数目: -h或--human-r ...

  5. javax.inject包

    javax.inject包 java提出的依赖注入标准,有别于以下传统的对象获取方式 构造方法 工厂模式 服务器定位模式(e.g. JNDI) 开发过程中是会有很多层层依赖的对象的,例如,Stopwa ...

  6. AOJ 2249 Road Construction (dijkstra)

    某国王需要修路,王国有一个首都和多个城市,需要修路.已经有修路计划了,但是修路费用太高. 为了减少修路费用,国王决定从计划中去掉一些路,但是需要满足一下两点: 保证所有城市都能连通 所有城市到首都的最 ...

  7. BZOJ1076 [SCOI2008]奖励关 概率 状态压缩动态规划

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1076 题意概括 有n个东西,k次扔出来.每次等概率扔出其中一个. 你可以拿这个东西,但是有条件,得 ...

  8. Linux- Showdown 命令详解

    语法 shutdown(选项)(参数) [选项] -c:当执行"shutdown -h 11:50"指令时,只要按+键就可以中断关机的指令: -f:重新启动时不执行fsck: -F ...

  9. P1025 数的划分

    P1025 数的划分f[i][j]表示把数i分成j份的方案数,分成两种情况,第一种是最小值是1,另一种是最小值不是1,对于不是1的情况,先都放一个1,那么f[i][j]=f[i-1][j-1]+f[i ...

  10. Java中递归和循环的优劣

    介绍: 你用你手中的钥匙打开一扇门,结果去发现前方还有一扇门,紧接着你又用钥匙打开了这扇门,然后你又看到一扇门......但是当你开到一扇门时,发现前方是一堵墙无路可走了,你选择原路返回--这就是递归 ...