Tree.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Ext.define('erp.view.common.init.Tree',{
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.inittree',
  4. id: 'inittree',
  5. width : '20%',
  6. margins : '0 0 -1 1',
  7. border : false,
  8. enableDD : false,
  9. split: true,
  10. title: '初始化项目',
  11. rootVisible: false,
  12. containerScroll : true,
  13. collapsible : true,
  14. autoScroll: false,
  15. useArrows: true,
  16. bodyStyle:'background-color:#f1f1f1;',
  17. initComponent : function(){
  18. this.getTreeRootNode(0);
  19. this.callParent(arguments);
  20. },
  21. getTreeRootNode: function(pid){
  22. var me = this;
  23. Ext.Ajax.request({//拿到tree数据
  24. url : basePath + 'system/initTree.action',
  25. params: {
  26. pid: pid
  27. },
  28. callback : function(options,success,response){
  29. var res = new Ext.decode(response.responseText);
  30. if(res.tree){
  31. var tree = me.parseTree(res.tree);
  32. if(pid == 0){
  33. Ext.getCmp('inittree').store.setRootNode({
  34. text: 'root',
  35. id: 'root',
  36. expanded: true,
  37. children: tree
  38. });
  39. } else {
  40. var record = me.selModel.lastSelected;
  41. record.appendChild(tree);
  42. record.expand(false, true);
  43. }
  44. } else if(res.exceptionInfo){
  45. showError(res.exceptionInfo);
  46. }
  47. }
  48. });
  49. },
  50. listeners: {
  51. scrollershow: function(scroller) {
  52. if (scroller && scroller.scrollEl) {
  53. scroller.clearManagedListeners();
  54. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  55. }
  56. }
  57. },
  58. parseTree: function(arr){
  59. var tree = new Array(),t;
  60. Ext.each(arr, function(r){
  61. t = new Object();
  62. t.id = r.in_id;
  63. t.text = r.in_desc;
  64. t.caller = r.in_caller;
  65. t.img = r.in_img;
  66. t.parentId = r.in_pid;
  67. t.leaf = r.in_leaf == 1;
  68. tree.push(t);
  69. });
  70. return tree;
  71. }
  72. });