先看代码:

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. css 文件连接不到网页

    css 文件连接不到网页 编码错误,将编码改为utf-8 Rom后正常

  2. PHP实现简单倒计时

    PHP实现倒计时代码示例如下: <?php $time1 = time(); $time2 = strtotime("2018-10-1"); $time3 = strtot ...

  3. hdu1556 树状数组区间更新单点查询板子

    就是裸的区间更新: 相对于直观的线段树的区间更新,树状数组的区间更新原理不太相同:由于数组中的一个结点控制的是一块区间,当遇到更新[l,r]时,先将所有能控制到 l 的结点给更新了,这样一来就是一下子 ...

  4. pytest十:用例 a 失败,跳过测试用例 b 和 c 并标记失败 xfail

    当用例 a 失败的时候,如果用例 b 和用例 c 都是依赖于第一个用例的结果,那可以直接跳过用例 b 和 c 的测试,直接给他标记失败 xfail用到的场景,登录是第一个用例,登录之后的操作 b 是第 ...

  5. python 全栈开发,Day58(bootstrap组件,bootstrap JavaScript 插件,后台模板,图表插件,jQuery插件库,Animate.css,swiper,运行vue项目)

    一.bootstrap组件 无数可复用的组件,包括字体图标.下拉菜单.导航.警告框.弹出框等更多功能. 组件和插件的区别? 插件:一个功能,比如js文件 组件:html css js 组件包含插件 面 ...

  6. node.js开发博客系统---前端项目搭建(一)

    Express: https://github.com/petecoop/generator-express 安装node.js和npm 执行: npm install -g yo npm insta ...

  7. python访问百度地图接口并返回信息

    import urllib.parse import urllib.request data = urllib.parse.urlencode({'address': '广东省湛江市霞山区', 'ou ...

  8. thinkphp自定义分页类

    先来看下这个分页的样式,没写css,确实丑 什么时候写样式再来上传下css吧...... 就是多一个页面跳转功能 先把这个代码贴一下 <?php namespace Component; cla ...

  9. 敌兵布阵 HDU1166

    基础线段树 #include<cstdio> #include<iostream> using namespace std; int n,p,a,b,m,x,y,ans; st ...

  10. Java Web 之javabeans

    Java遇见HTML——JSP篇之JavaBeans: http://www.cnblogs.com/Qian123/p/5277425.html