dhtmlxtree 如何得到xml,json等文件中的自定义的属性值
先看代码:
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
| 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 |
| 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等文件中的自定义的属性值的更多相关文章
- 在CSV文件中增加一列属性值
具体参见:系统管理\将文件夹复制到列表中的远程主机 修改前: column1, column2 1,b 2,c 3,5 修改后: column1, column2, column3 1,b, ...
- Spring boot中普通工具类不能使用@Value注入yml文件中的自定义参数的问题
在写一个工具类的时候,因为要用到yml中的自定义参数,使用@Value发现值不能正常注入,都显示为null: yml文件中的自定义格式 调用工具类的时候不能new的方式 要使用@Autowired的方 ...
- js中获取css样式属性值
关于js中style,currentStyle和getComputedStyle几个注意的地方 (1)用js的style只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的.针对css ...
- JSON字符串反序列化成对象_部分属性值反序列化失败
简介:本人在开发webapi接口时遇到了:一个复杂的Json字符串在反序列化为对象时报,无法发序列化其中的一个属性对象? 使用方法: InternalRecommendRequestFormModel ...
- MVC过滤器中获取实体类属性值
本文地址:http://www.cnblogs.com/outtamyhead/p/3616913.html,转载请保留本地址! 最近在项目遇到了这个问题:获取Action行参中实体类的属性值,主要的 ...
- 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 ...
- 使用json读写文件中的数据
把json的数据写入到文件中 import json with open('data.json','w+') as f: json.dump({"name":"张彪&qu ...
- castle windsor学习----- Referencing types in XML 在xm文件中引用类型
当从xml引用installer的语法如下 <install type="Acme.Crm.Infrastructure.ServicesInstaller, Acme.Crm.Inf ...
- 微信小程序wxml文件中调用自定义函数
想在微信小程序的wxml文件里自如的像vue那样调用自定义的方法,发现并不成功,得利用WXS脚本语言. WXS脚本语言是 WeiXin Script 脚本语言的简称,是JavaScript.JSON. ...
随机推荐
- Android 动画:你真的会使用插值器与估值器吗?
目录 目录 1. 插值器(Interpolator) 1.1 简介 定义:一个接口 作用:设置 属性值 从初始值过渡到结束值 的变化规律 如匀速.加速 & 减速 等等 即确定了 动画效果变 ...
- vue-cli之webpack的proxyTable无效的解决方案
最近遇到这个需要单页访问跨域后台的问题 可以按照如下设置: proxyTable: { '/list': { target: 'http://api.xxxxxxxx.com', pathRewrit ...
- 步步为营-71-asp.net的简单练习(图片处理)
1 原有图片添加水印 1.1 封装一个类,用于获取文件路径 using System; using System.Collections.Generic; using System.IO; using ...
- DDD模型领域WF到领域层(十五)
实现超市的结算系统: 计算相应的优惠方式的接口 public interface ICompute { double GetResultTotalMoney(double TotalMoney); } ...
- CentOS6.8安装RabbitMQ
1.安装erlang 安装依赖包: yum install xmlto gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC ...
- asp.net core 微信公众号支付(扫码支付,H5支付,公众号支付,app支付)之3
在微信公众号中访问手机网站,当需要调用支付时候无法使用H5支付,只有使用微信公众号支付,使用公众号支付用户必须关注该公众号同时该公众号必须开通公众号支付功能. 1.获取用户的OpenId ,参考之前写 ...
- python全栈开发day14--内置函数和匿名函数
- Codeforces 295C Greg and Friends BFS
Greg and Friends BFS的过程中维护一下方案数. 我个人感觉不是很好想, 但是写出来之后怎么感觉这题这么SB啊啊. #include<bits/stdc++.h> #def ...
- Linux命令02--系统管理
<1>查看当前日历:cal <2>显示或者设置时间 设置时间格式(需要管理员权限):一般都是有ntp服务的,你的系统会根据这个对照互联网时间 <3>查看进程信息:p ...
- CSS 1. 选择器
1.css的介绍 CSS是指层叠样式表(Cascading Style Sheets),样式定义如何显示HTML元素,样式通常又会存在于样式表中.也就是说把HTML元素的样式都统一收集起来写在一个地方 ...