id_tree.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /**
  2. * Created by Mai on 2017/3/17.
  3. */
  4. var idTree = {
  5. createNew: function (setting) {
  6. var _setting = {
  7. id: 'id',
  8. pid: 'pid',
  9. nid: 'nid',
  10. rootId: -1,
  11. autoUpdate: false
  12. };
  13. var _eventType = {
  14. editedData: 'editedData'
  15. };
  16. var tools = {
  17. findNode: function (nodes, check) {
  18. for (var i = 0; i < nodes.length; i++) {
  19. if (check(nodes[i])) {
  20. return nodes[i];
  21. }
  22. }
  23. return null;
  24. },
  25. reSortNodes: function (nodes, recursive) {
  26. var temp = [], first;
  27. var findFirstNode = function (nodes) {
  28. return tools.findNode(nodes, function (node) {
  29. return node.preSibling === null;
  30. });
  31. };
  32. var moveNode = function (node, orgArray, newArray, newIndex) {
  33. var next;
  34. orgArray.splice(orgArray.indexOf(node), 1);
  35. newArray.splice(newIndex, 0, node);
  36. if (node.getNextSiblingID() !== -1) {
  37. next = node.nextSibling;
  38. if (next && (orgArray.indexOf(next) >= 0)) {
  39. moveNode(next, orgArray, newArray, newIndex + 1);
  40. }
  41. }
  42. };
  43. if (nodes.length === 0) {
  44. return nodes;
  45. }
  46. if (recursive) {
  47. nodes.forEach(function (node) {
  48. node.children = tools.reSortNodes(node.children, recursive);
  49. });
  50. }
  51. while (nodes.length > 0) {
  52. first = findFirstNode(nodes);
  53. first = first ? first : nodes[0];
  54. moveNode(first, nodes, temp, temp.length);
  55. }
  56. nodes = null;
  57. tools.reSiblingNodes(temp);
  58. return temp;
  59. },
  60. reSiblingNodes: function (nodes) {
  61. var i;
  62. for (i = 0; i < nodes.length; i++) {
  63. nodes[i].preSibling = (i === 0) ? null : nodes[i - 1];
  64. nodes[i].nextSibling = (i === nodes.length - 1) ? null : nodes[i + 1];
  65. }
  66. },
  67. // 在nodes中,从iIndex(包括)开始全部移除
  68. removeNodes: function (tree, parent, iIndex, count) {
  69. var children = parent ? parent.children : tree.roots;
  70. var pre = (iIndex < 0 || iIndex >= children.length) ? null : children[iIndex].preSibling;
  71. var next = (pre && iIndex + count - 1 < children.length) ? children[iIndex + count] : null;
  72. if (pre) {
  73. pre.setNextSibling(next);
  74. } else if (next) {
  75. next.preSibling = null;
  76. }
  77. if (arguments.length === 4) {
  78. children.splice(iIndex, count);
  79. } else {
  80. children.splice(iIndex, children.length - iIndex);
  81. }
  82. },
  83. // 在parent.children/tree.roots中增加nodes, 位置从index开始
  84. addNodes: function (tree, parent, nodes, iIndex) {
  85. var children = parent ? parent.children : tree.roots;
  86. var pre, next, i;
  87. if (nodes.length === 0) { return; }
  88. if (arguments.length === 4) {
  89. pre = (iIndex <= 0 || iIndex > children.length) ? null : children[iIndex - 1];
  90. next = pre ? pre.nextSibling : null;
  91. } else if (arguments.length === 3) {
  92. pre = children.length === 0 ? null : children[children.length - 1];
  93. next = null;
  94. }
  95. if (pre) {
  96. pre.setNextSibling(nodes[0]);
  97. } else {
  98. nodes[0].preSibling = null;
  99. }
  100. nodes[nodes.length - 1].setNextSibling(next);
  101. for (i = 0; i < nodes.length; i++) {
  102. if (arguments.length === 4) {
  103. children.splice(iIndex + i, 0, nodes[i]);
  104. } else if (arguments.length === 3) {
  105. children.push(nodes[i]);
  106. }
  107. nodes[i].setParent(parent ? parent : null);
  108. }
  109. },
  110. sortTreeItems: function (tree) {
  111. var addItems = function (items) {
  112. var i;
  113. for (i = 0; i < items.length; i++) {
  114. tree.items.push(items[i]);
  115. addItems(items[i].children);
  116. }
  117. };
  118. tree.items.splice(0, tree.items.length);
  119. addItems(tree.roots);
  120. },
  121. addUpdateDataForParent: function (datas, nodes, pid) {
  122. nodes.forEach(function (node) {
  123. datas.push({type: 'update', data: node.tree.getDataTemplate(node.getID(), pid, node.getNextSiblingID())});
  124. });
  125. },
  126. addUpdateDataForNextSibling: function (datas, node, nid) {
  127. if (node) {
  128. datas.push({type: 'update', data: node.tree.getDataTemplate(node.getID(), node.getParentID(), nid)});
  129. }
  130. }
  131. };
  132. var Node = function (tree, data) {
  133. // 以下的属性,本单元外均不可直接修改
  134. this.tree = tree;
  135. this.data = data;
  136. this.children = [];
  137. this.parent = null;
  138. this.nextSibling = null;
  139. this.preSibling = null;
  140. this.expanded = true;
  141. this.visible = true;
  142. this.visible = true;
  143. };
  144. Node.prototype.getID = function () {
  145. return this.data[this.tree.setting.id];
  146. };
  147. Node.prototype.getParentID = function () {
  148. return this.parent ? this.parent.getID() : -1;
  149. };
  150. Node.prototype.getNextSiblingID = function () {
  151. return this.nextSibling ? this.nextSibling.getID() : -1;
  152. };
  153. Node.prototype.setParent = function (parent) {
  154. this.parent = parent;
  155. if (this.tree.setting.autoUpdate) {
  156. this.data[this.tree.setting.pid] = this.getParentID();
  157. }
  158. };
  159. Node.prototype.setNextSibling = function (nextSibling) {
  160. this.nextSibling = nextSibling;
  161. if (nextSibling) {
  162. nextSibling.preSibling = this;
  163. }
  164. if (this.tree.setting.autoUpdate) {
  165. this.data[this.tree.setting.nid] = this.getNextSiblingID();
  166. }
  167. }
  168. Node.prototype.firstChild = function () {
  169. return this.children.length === 0 ? null : this.children[0];
  170. };
  171. Node.prototype.lastChild = function () {
  172. return this.children.length === 0 ? null : this.children[this.children.length - 1];
  173. };
  174. Node.prototype.depth = function () {
  175. return this.parent ? this.parent.depth() + 1 : 0;
  176. };
  177. Node.prototype.isFirst = function () {
  178. if (this.parent) {
  179. return this.parent.children.indexOf(this) === 0 ? true : false;
  180. } else {
  181. return this.tree.roots.indexOf(this) === 0 ? true : false;
  182. }
  183. };
  184. Node.prototype.isLast = function () {
  185. if (this.parent) {
  186. return this.parent.children.indexOf(this) === this.parent.children.length - 1 ? true : false;
  187. } else {
  188. return this.tree.roots.indexOf(this) === this.tree.roots.length - 1 ? true : false;
  189. }
  190. };
  191. Node.prototype.siblingIndex = function () {
  192. return this.parent ? this.parent.children.indexOf(this) : this.tree.roots.indexOf(this);
  193. };
  194. Node.prototype.posterityCount = function () {
  195. var iCount = 0;
  196. if (this.children.length !== 0) {
  197. iCount += this.children.length;
  198. this.children.forEach(function (child) {
  199. iCount += child.posterityCount();
  200. });
  201. }
  202. return iCount;
  203. /*return (node.children.length === 0) ? 0 : node.children.reduce(function (x, y) {
  204. return x.posterityCount() + y.posterityCount();
  205. }) + node.children.count;*/
  206. };
  207. Node.prototype.setExpanded = function (expanded) {
  208. var setNodesVisible = function (nodes, visible) {
  209. nodes.forEach(function (node) {
  210. node.visible = visible;
  211. setNodesVisible(node.children, visible && node.expanded);
  212. })
  213. };
  214. this.expanded = expanded;
  215. setNodesVisible(this.children, expanded);
  216. };
  217. /*Node.prototype.vis = function () {
  218. return this.parent ? this.parent.vis() && this.parent.expanded() : true;
  219. };*/
  220. Node.prototype.serialNo = function () {
  221. return this.tree.items.indexOf(this);
  222. };
  223. Node.prototype.addChild = function (node) {
  224. var preSibling = this.children.length === 0 ? null : this.children[this.children.length - 1];
  225. node.parent = this;
  226. if (preSibling) {
  227. preSibling.nextSibling = node;
  228. }
  229. node.preSibling = preSibling;
  230. this.children.push(node);
  231. };
  232. Node.prototype.removeChild = function (node) {
  233. var preSibling = node.preSibling, nextSibling = node.nextSibling;
  234. if (preSibling) {
  235. preSibling.nextSibling = nextSibling;
  236. }
  237. if (nextSibling) {
  238. nextSibling.preSibling = preSibling;
  239. }
  240. this.children.splice(node.siblingIndex, 1);
  241. };
  242. Node.prototype.canUpLevel = function () {
  243. return this.parent ? true : false;
  244. };
  245. Node.prototype.getUpLevelData = function () {
  246. var data = [];
  247. if (this.canUpLevel()) {
  248. if (!this.isLast()) {
  249. tools.addUpdateDataForParent(data, this.parent.children.slice(this.siblingIndex() + 1), this.getID());
  250. }
  251. if (this.preSibling) {
  252. tools.addUpdateDataForNextSibling(data, this.preSibling, this.tree.setting.rootId);
  253. }
  254. tools.addUpdateDataForNextSibling(data, this.parent, this.getID());
  255. data.push({type: 'update', data: this.tree.getDataTemplate(this.getID(), this.parent.getParentID(), this.parent.getNextSiblingID())});
  256. }
  257. return data;
  258. };
  259. Node.prototype.upLevel = function () {
  260. var result = {success: false, updateDatas: []};
  261. var iIndex = this.parent.children.indexOf(this), orgParent = this.parent, newNextSibling = this.parent.nextSibling;
  262. if (this.canUpLevel) {
  263. // NextSiblings become child
  264. tools.addNodes(this.tree, this, this.parent.children.slice(iIndex + 1));
  265. // Orginal Parent remove node and nextSiblings
  266. tools.removeNodes(this.tree, this.parent, iIndex);
  267. // New Parent add node
  268. tools.addNodes(this.tree, this.parent.parent, [this], this.parent.siblingIndex() + 1);
  269. if (!this.expanded) {
  270. this.setExpanded(true);
  271. }
  272. result.success = true;
  273. }
  274. return result;
  275. };
  276. Node.prototype.canDownLevel = function () {
  277. return !this.isFirst();
  278. };
  279. Node.prototype.getDownLevelData = function () {
  280. var data = [];
  281. if (this.canDownLevel()) {
  282. if (this.preSibling.children.length !== 0) {
  283. tools.addUpdateDataForNextSibling(data, this.preSibling.lastChild(), this.getID());
  284. }
  285. tools.addUpdateDataForNextSibling(data, this.preSibling, this.getNextSiblingID());
  286. data.push({type: 'update', data: this.tree.getDataTemplate(this.getID(), this.preSibling.getID(), this.tree.setting.rootId)});
  287. }
  288. return data;
  289. };
  290. Node.prototype.downLevel = function () {
  291. var success = false, iIndex = this.parent ? this.parent.children.indexOf(this) : this.tree.roots.indexOf(this);
  292. var newParent = this.preSibling;
  293. if (this.canDownLevel()) {
  294. tools.removeNodes(this.tree, this.parent, this.siblingIndex(), 1);
  295. tools.addNodes(this.tree, this.preSibling, [this]);
  296. if (!newParent.expanded) {
  297. newParent.setExpanded(true);
  298. }
  299. success = true;
  300. }
  301. return success;
  302. };
  303. Node.prototype.canUpMove = function () {
  304. return !this.isFirst();
  305. };
  306. Node.prototype.getUpMoveData = function () {
  307. var data = [];
  308. if (this.canUpMove()) {
  309. if (this.preSibling.preSibling) {
  310. tools.addUpdateDataForNextSibling(data, this.preSibling.preSibling, this.getID());
  311. }
  312. tools.addUpdateDataForNextSibling(data, this.preSibling, this.getNextSiblingID());
  313. tools.addUpdateDataForNextSibling(data, this, this.preSibling.getID());
  314. }
  315. return data;
  316. };
  317. Node.prototype.upMove = function () {
  318. var success = false;
  319. var iIndex = this.siblingIndex(), belongArray = this.parent ? this.parent.children : this.tree.roots, orgPre = this.preSibling;
  320. if (this.canUpMove()) {
  321. if (orgPre.preSibling) {
  322. orgPre.preSibling.setNextSibling(this);
  323. } else {
  324. this.preSibling = null;
  325. }
  326. orgPre.setNextSibling(this.nextSibling);
  327. this.setNextSibling(orgPre);
  328. belongArray.splice(iIndex, 1);
  329. belongArray.splice(iIndex - 1, 0, this);
  330. tools.sortTreeItems(this.tree);
  331. success = true;
  332. }
  333. return success;
  334. };
  335. Node.prototype.canDownMove = function () {
  336. return !this.isLast();
  337. };
  338. Node.prototype.getDownMoveData = function () {
  339. var data = [];
  340. if (this.canDownMove()) {
  341. if (this.preSibling) {
  342. tools.addUpdateDataForNextSibling(data, this.preSibling, this.nextSibling.getID());
  343. }
  344. tools.addUpdateDataForNextSibling(data, this, this.nextSibling.getNextSiblingID());
  345. tools.addUpdateDataForNextSibling(data, this.nextSibling, this.getID());
  346. }
  347. return data;
  348. };
  349. Node.prototype.downMove = function () {
  350. var success = false;
  351. var iIndex = this.siblingIndex(), belongArray = this.parent ? this.parent.children : this.tree.roots, orgNext = this.nextSibling;
  352. if (this.canDownMove()) {
  353. if (this.preSibling) {
  354. this.preSibling.setNextSibling(orgNext);
  355. } else if (orgNext) {
  356. orgNext.preSibling = null;
  357. }
  358. this.setNextSibling(orgNext.nextSibling);
  359. orgNext.setNextSibling(this);
  360. belongArray.splice(iIndex, 1);
  361. belongArray.splice(iIndex + 1, 0, this);
  362. tools.sortTreeItems(this.tree);
  363. success = true;
  364. }
  365. return success;
  366. };
  367. var Tree = function (setting) {
  368. this.nodes = {};
  369. this.roots = [];
  370. this.items = [];
  371. this.setting = setting;
  372. this.prefix = 'id_';
  373. this.selected = null;
  374. this.event = {};
  375. this.eventType = _eventType;
  376. };
  377. Tree.prototype.getDataTemplate = function (id, pid, nid) {
  378. var data = {};
  379. data[this.setting.id] = id;
  380. data[this.setting.pid] = pid;
  381. data[this.setting.nid] = nid;
  382. return data;
  383. };
  384. Tree.prototype.maxNodeID = (function () {
  385. var maxID = 0;
  386. return function (ID) {
  387. if (arguments.length === 0) {
  388. return maxID;
  389. } else {
  390. maxID = Math.max(maxID, ID);
  391. }
  392. };
  393. })();
  394. Tree.prototype.rangeNodeID = (function () {
  395. var rangeID = -1;
  396. return function (ID) {
  397. if (arguments.length === 0) {
  398. return rangeID;
  399. } else {
  400. rangeID = Math.max(rangeID, ID);
  401. }
  402. }
  403. })();
  404. Tree.prototype.newNodeID = function () {
  405. if (this.rangeNodeID() === -1) {
  406. return this.maxNodeID() + 1;
  407. } else {
  408. if (this.maxNodeID() < this.rangeNodeID()) {
  409. return this.maxNodeID() + 1;
  410. } else {
  411. return -1;
  412. }
  413. }
  414. /*if (this.maxID >= this.rangeNodeID() || this.rangeNodeID === -1) {
  415. return -1;
  416. } else {
  417. return this.maxNodeID() + 1;
  418. }*/
  419. };
  420. Tree.prototype.clearNodes = function () {
  421. this.nodes = {};
  422. this.roots = [];
  423. this.items = [];
  424. };
  425. Tree.prototype.loadDatas = function (datas) {
  426. var prefix = this.prefix, i, node, parent, next, that = this;
  427. this.nodes = {};
  428. this.roots = [];
  429. this.items = [];
  430. // prepare index
  431. datas.forEach(function (data) {
  432. var node = new Node(that, data);
  433. that.nodes[prefix + data[that.setting.id]] = node;
  434. that.maxNodeID(data[that.setting.id]);
  435. });
  436. // set parent by pid, set nextSibling by nid
  437. datas.forEach(function (data) {
  438. node = that.nodes[prefix + data[that.setting.id]];
  439. if (data[that.setting.pid] === that.setting.rootId) {
  440. that.roots.push(node);
  441. } else {
  442. parent = that.nodes[prefix + data[that.setting.pid]];
  443. if (parent) {
  444. node.parent = parent;
  445. parent.children.push(node);
  446. }
  447. }
  448. if (data[that.setting.nid] !== that.setting.rootId) {
  449. next = that.nodes[prefix + data[that.setting.nid]];
  450. if (next) {
  451. node.nextSibling = next;
  452. next.preSibling = node;
  453. }
  454. }
  455. })
  456. // sort by nid
  457. this.roots = tools.reSortNodes(this.roots, true);
  458. tools.sortTreeItems(this);
  459. };
  460. Tree.prototype.firstNode = function () {
  461. return this.roots.length === 0 ? null : this.roots[0];
  462. };
  463. Tree.prototype.findNode = function (id) {
  464. return this.nodes[this.prefix + id];
  465. };
  466. Tree.prototype.count = function () {
  467. var iCount = 0;
  468. if (this.roots.length !== 0) {
  469. iCount += this.roots.length;
  470. this.roots.forEach(function (node) {
  471. iCount += node.posterityCount();
  472. });
  473. }
  474. return iCount;
  475. };
  476. Tree.prototype.insert = function (parentID, nextSiblingID) {
  477. var newID = this.newNodeID(), node = null, data = {};
  478. var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
  479. var nextSibling = nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
  480. if (newID !== -1) {
  481. data = {};
  482. data[this.setting.id] = newID;
  483. data[this.setting.pid] = parent ? parent.getID() : this.setting.rootId;
  484. data[this.setting.nid] = nextSibling ? nextSibling.getID() : this.setting.rootId;
  485. node = new Node(this, data);
  486. if (nextSibling) {
  487. tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
  488. } else {
  489. tools.addNodes(this, parent, [node]);
  490. }
  491. this.nodes[this.prefix + newID] = node;
  492. tools.sortTreeItems(this);
  493. this.maxNodeID(newID);
  494. }
  495. return node;
  496. };
  497. Tree.prototype.getInsertData = function (parentID, nextSiblingID) {
  498. var data = [];
  499. var newID = this.newNodeID();
  500. var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
  501. var nextSibling = nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
  502. if (newID !== -1) {
  503. data.push({type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, nextSibling ? nextSibling.getID() : this.setting.rootId)});
  504. if (nextSibling && nextSibling.preSibling) {
  505. tools.addUpdateDataForNextSibling(data, nextSibling.preSibling, newID);
  506. } else if (parent && parent.children.length !== 0) {
  507. tools.addUpdateDataForNextSibling(data, parent.lastChild(), newID);
  508. } else if (!parent && this.roots.length !== 0) {
  509. tools.addUpdateDataForNextSibling(data, this.roots[this.roots.length - 1], newID);
  510. }
  511. }
  512. return data;
  513. };
  514. Tree.prototype.insertByData = function (data, parentID, nextSiblingID) {
  515. var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
  516. var nextSibling = nextSiblingID === -1 ? null : this.nodes[this.prefix + nextSiblingID];
  517. var node = this.nodes[this.prefix + data[this.setting.id]];
  518. if (node) {
  519. return node;
  520. } else {
  521. node = new Node(this, data);
  522. if (nextSibling) {
  523. tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
  524. } else {
  525. tools.addNodes(this, parent, [node]);
  526. }
  527. this.nodes[this.prefix + data[this.setting.id]] = node;
  528. tools.sortTreeItems(this);
  529. this.maxNodeID( data[this.setting.id]);
  530. return node;
  531. }
  532. };
  533. Tree.prototype.delete = function (node) {
  534. var success = false, that = this;
  535. var deleteIdIndex = function (nodes) {
  536. nodes.forEach(function (node) {
  537. delete that.nodes[that.prefix + node.getID()];
  538. deleteIdIndex(node.children);
  539. })
  540. }
  541. if (node) {
  542. deleteIdIndex([node]);
  543. //delete this.nodes[this.prefix + node.getID()];
  544. if (node.preSibling) {
  545. node.preSibling.setNextSibling(node.nextSibling);
  546. } else if (node.nextSibling) {
  547. node.nextSibling.preSibling = null;
  548. }
  549. if (node.parent) {
  550. node.parent.children.splice(node.siblingIndex(), 1);
  551. } else {
  552. this.roots.splice(node.siblingIndex(), 1);
  553. }
  554. tools.sortTreeItems(this);
  555. success = true;
  556. }
  557. return success;
  558. };
  559. Tree.prototype.singleDelete = function (node) {//删除本身不删除子项
  560. let that = this;
  561. let success = false;
  562. delete that.nodes[that.prefix + node.getID()];//删除本身
  563. if(node.children.length>0){
  564. if(node.preSibling){//子项变成前兄弟的子项
  565. for(let c of node.children){
  566. node.preSibling.addChild(c);
  567. }
  568. }else if(node.nextSibling){//没有前兄弟,有后兄弟
  569. let oldChild = node.parent.children;
  570. node.parent.children = [];
  571. for(let c of node.children){
  572. node.parent.addChild(c);
  573. }
  574. for(let oc of oldChild){
  575. node.parent.addChild(oc);
  576. }
  577. }else {//都没有的情况
  578. for(let c of node.children){
  579. node.parent.addChild(c);
  580. }
  581. }
  582. tools.sortTreeItems(this);
  583. success = true;
  584. }
  585. return success;
  586. };
  587. Tree.prototype.getDeleteData = function (node) {
  588. var data = [];
  589. var addUpdateDataForDelete = function (datas, nodes) {
  590. nodes.forEach(function (node) {
  591. var delData = {};
  592. delData[node.tree.setting.id] = node.getID();
  593. datas.push({type: 'delete', data: delData});
  594. addUpdateDataForDelete(datas, node.children);
  595. })
  596. };
  597. if (node) {
  598. addUpdateDataForDelete(data, [node]);
  599. if (node.preSibling) {
  600. tools.addUpdateDataForNextSibling(data, node.preSibling, node.getNextSiblingID());
  601. }
  602. }
  603. return data;
  604. };
  605. /*Tree.prototype.editedData = function (field, id, newText) {
  606. var node = this.findNode(id), result = {allow: false, nodes: []};
  607. if (this.event[this.eventType.editedData]) {
  608. return this.event[this.eventType.editedData](field, node.data);
  609. } else {
  610. node.data[field] = newText;
  611. result.allow = true;
  612. return result;
  613. }
  614. };*/
  615. Tree.prototype.bind = function (eventName, eventFun) {
  616. this.event[eventName] = eventFun;
  617. };
  618. return new Tree(setting);
  619. },
  620. updateType: {update: 'update', new: 'new', delete: 'delete'}
  621. };