- 注册时间
- 2014-7-21
- 最后登录
- 2022-7-26
- 阅读权限
- 150
- 积分
- 18264
- 精华
- 0
- 帖子
- 8338
|
nbakill2 发表于 2019-5-9 10:19
你这个arraytoTree方法.
第一个参数 data 是json字符串,还是json数组对象?
var data=[] //id,pid对应关系的列表形态数组
var treeData=mini.arrayToTree(data,"children","id","pid");
//children 生成的树形数据里面,带出子节点的字段
//id,pid 列表数据里面形成对应关系的字段- var data = [
- { id: "base", text: "Base" },
- { id: "ajax", text: "Ajax", pid: "base" },
- { id: "json", text: "JSON", pid: "base" },
- { id: "date", text: "Date", pid: "base" },
- { id: "control", text: "Control", pid: "base" },
- { id: "forms", text: "Forms", pid: "base" },
- { id: "button", text: "Button", pid: "forms" },
- { id: "listbox", text: "ListBox", pid: "forms" },
- { id: "checkboxlist", text: "CheckBoxList", pid: "forms" },
- { id: "lists", text: "Lists" },
- { id: "datagrid", text: "DataGrid", pid: "lists" },
- { id: "tree", text: "Tree", pid: "lists" },
- { id: "treegrid", text: "TreeGrid ", pid: "lists" }
- ];
- var treeData = mini.arrayToTree(data, "children", "id", "pid")
-
- [{
- "id": "base",
- "text": "Base",
- "children": [{
- "id": "ajax",
- "text": "Ajax",
- "pid": "base"
- },
- {
- "id": "json",
- "text": "JSON",
- "pid": "base"
- },
- {
- "id": "date",
- "text": "Date",
- "pid": "base"
- },
- {
- "id": "control",
- "text": "Control",
- "pid": "base"
- },
- {
- "id": "forms",
- "text": "Forms",
- "pid": "base",
- "children": [{
- "id": "button",
- "text": "Button",
- "pid": "forms"
- },
- {
- "id": "listbox",
- "text": "ListBox",
- "pid": "forms"
- },
- {
- "id": "checkboxlist",
- "text": "CheckBoxList",
- "pid": "forms"
- }]
- }]
- },
- {
- "id": "lists",
- "text": "Lists",
- "children": [{
- "id": "datagrid",
- "text": "DataGrid",
- "pid": "lists"
- },
- {
- "id": "tree",
- "text": "Tree",
- "pid": "lists"
- },
- {
- "id": "treegrid",
- "text": "TreeGrid ",
- "pid": "lists"
- }]
- }]
复制代码 |
|