Ext.tree.Panel实现单选,多选

Extjs

  1 var productCategoryTreeLookUpFn = function(callback) {
  2     var productCategoryLookUpWindow;
  3     var productCategoryTreeStore;
  4     var productCategoryTreeMenu;
  5
  6     if (!productCategoryLookUpWindow) {
  7
  8         // 加载菜单树
  9         productCategoryTreeStore = Ext.create(‘Ext.data.TreeStore‘, {
 10             fields : [‘id‘, ‘text‘],
 11             proxy: {
 12                 type: ‘ajax‘,
 13                 url: COMMON.APP_URL + ‘/view/master/selectProductCategoryForComboBoxTree.action‘
 14             },
 15             root: {
 16                 id: ‘0‘,
 17                 text : "产品分类",
 18                 expanded: true
 19             }
 20         });
 21
 22         var beforNode = null;
 23         productCategoryTreeMenu = Ext.create(‘Ext.tree.Panel‘, {
 24             store: productCategoryTreeStore,
 25             rootVisible : false,
 26             height : 300,
 27             animate : true, // 开启动画效果
 28             enableDD : false, // 不允许子节点拖动
 29             border : false, // 没有边框
 30             singleClickExpand : true,
 31             listeners : {
 32                 checkchange : function(node, checked, eOpts) {
 33 //                    setChildChecked(node, checked);
 34                     if(node.isNode){
 35                         if(beforNode != null){//把上一次选中节点取消选择,实现单选
 36                             beforNode.set("checked",false);
 37                         }
 38                         beforNode = node;
 39 //                        node.collapse();
 40 //                        node.cascadeBy(function(node) {
 41 //                            node.set("checked",checked);
 42 //                        });
 43                     }
 44                 }
 45             }
 46         });
 47
 48         function setChildChecked(node, checked){
 49             node.set({checked:checked});
 50             if(node.hasChildNodes()){
 51                 node.eachChild(function(child) {
 52                     setChildChecked(child, checked);
 53                 });
 54             }
 55         }
 56
 57         function setParentChecked(node, checked){
 58             node.set({checked:checked});
 59             var parentNode = node.parentNode;
 60             if(parentNode != null){
 61                 var flag = false;
 62                 parentNode.eachChild(function(child) {
 63                     if(child.data.checked == true){
 64                         flag = true;
 65                     }
 66                 });
 67                 if (checked == false) {
 68                     if(!flag){
 69                         setParentChecked(parentNode, checked);
 70                     }
 71                 } else {
 72                     if(flag){
 73                         setParentChecked(parentNode, checked);
 74                     }
 75                 }
 76              }
 77         }
 78
 79         productCategoryLookUpWindow = Ext.create(‘Ext.window.Window‘, {
 80             title : ‘产品分类信息‘,
 81             autoShow: true,
 82             width : 400,
 83             constrain : true,
 84             constrainHeader : true,
 85             maximizable : false,
 86             minimizable : false,
 87             resizable : false,
 88             closable : false,
 89             buttonAlign : ‘right‘,
 90             animateTarget: Ext.getBody(),
 91             modal : true,
 92             plain : true,
 93             border : true,
 94             closeAction : ‘destroy‘,
 95             items : [productCategoryTreeMenu],
 96             buttons : [{
 97                 text : ‘确定‘,
 98                 handler : function() {
 99                     var checkNodeArray = productCategoryTreeMenu.getChecked();
100                     var checkNodeString = ‘‘;
101                     var checkNodeTextString = ‘‘;
102                     for (var index = 0; index < checkNodeArray.length; index++) {
103                         checkNodeString += checkNodeArray[0].data.id;
104                         checkNodeTextString += checkNodeArray[0].data.qtip;
105                     }
106                     if (Ext.isFunction(callback)) {
107                         callback(checkNodeString, checkNodeTextString);
108                     }
109                     productCategoryLookUpWindow.destroy();
110                 }
111             }, {
112                 text : ‘关闭‘,
113                 handler : function() {
114                     productCategoryLookUpWindow.destroy();
115                 }
116             }]
117         });
118
119     }
120
121     productCategoryLookUpWindow.show();
122
123 };

Java

for (ProductCategoryVO dbVo : productCategoryVOList) {
                JSONObject obj = new JSONObject();
                obj.put("id", dbVo.getCategoryIdFull());
                obj.put("text", dbVo.getCategoryName());
                obj.put("qtip", dbVo.getCategoryNameFull());
                obj.put("leaf", !new Boolean(dbVo.getIsExistChildNode()));
                obj.put("checked", new Boolean(false));
//                obj.put("isExistChildNode", new Boolean(dbVo.getIsExistChildNode()));
//                obj.put("categoryId", dbVo.getCategoryId());
//                obj.put("categoryName", dbVo.getCategoryName());
//                obj.put("categoryIdFull", dbVo.getCategoryIdFull());
//                obj.put("categoryNameFull", dbVo.getCategoryNameFull());
//                obj.put("parentIdFull", dbVo.getParentIdFull());
//                obj.put("parentNameFull", dbVo.getParentNameFull());
//                obj.put("recordId", dbVo.getId());
//                obj.put("nodeLevel", dbVo.getNodeLevel());
                jsonArray.add(obj);
            }

原文地址:https://www.cnblogs.com/BobXie85/p/8269129.html

时间: 2024-08-02 23:14:43

Ext.tree.Panel实现单选,多选的相关文章

Extjs学习笔记--Ext.tree.Panel

Ext.create('Ext.tree.Panel', { title: 'Simple Tree', width: 200, height: 150, store: store, rootVisible: false, //是否显示根节点 lines:false,//是否显示树节点前面的虚线 参考图A,B renderTo: Ext.getBody() });            图片A                           图片B

Ext.tree.panel 后端动态加载json数据

首先建一个bean类,如: package ***.bean; import java.io.Serializable;import java.util.List; public class Menu implements Serializable { private static final long serialVersionUID = 1L; private String id; private String parentId;//设置父id和子id用来拼接children,设成字符串有利

解决Ext 4.0.7 tree.Panel横向不出滚动条,纵向滚动条失效的问题

/** * 重写Ext.tree.Panel afterlayout方法,解决横向不出滚动条,纵向滚动条失效的问题 * 1.显示grid的css滚动条,横向滚动条没有办法使标题一块儿滚动,所以隐藏掉 * 2.将grid的css纵向滚动条定位到最右侧 * 3.获取到ext自动添加的自己写的滚动条,将它remove掉 */ Ext.tree.Panel.override({ listeners:{ afterlayout : function(treePanel, eOpts){ var emBod

Ext.form.Panel表单面板

1.Ext.form.FormPanel支持的主要表单组件 ExtJS表单组件 说明 Xtype类型 Ext.form.field.CheckBox 复选框 checkboxfield Ext.form.CheckBoxGroup 复选框组 checkboxgroup Ext.form.field.ComboBox 下拉列表框 combo Ext.form.field.Date 日期选择框 datefield Ext.form.field.Display 文本显示组件 displayfield

【extjs】 extjs5 Ext.grid.Panel 搜索示例

先看效果图: 页面js: <script type="text/javascript"> /** * 日志类型 store * */ var logTypeStore = Ext.create('Ext.data.Store', { fields: ['type', 'name'], data : [ {"type":"1", "name":"登录日志"}, {"type":

Ext.grid.Panel表格特性Feature

Ext.grid.feature.Feature是一类针对Ext.grid.Panel 的特殊插件,提供了可以被扩展的基本模板方法.子类包括: 1.Ext.grid.feature.RowBody 表格行体 行体特性为表格追加了tr标签,跨越了原始表格的所有列,在表格中展示一些描述性的特殊信息时非常有用,行体在默认状态下是隐藏的,如果需要展示行体必须覆盖getAdditionalData方法,代码如下: //Ext.grid.feature.RowBody示例 Ext.onReady(funct

【extjs】 ext5 Ext.grid.Panel 分页,搜索

带有分页,搜索的grid. <%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8" %> <html> <head> <jsp:include page="../common/resource_classic.jsp"

Ext.grid.Panel表格分页存储过程

/*首先需要引入两个Extjs插件类 Ext.ux.data.PagingMemoryProxy和Ext.ux.ProgressBarPager这两个类*/ /*下面是控制弹出窗体放大缩小时窗体居中的方法*/ 1 var HotalOrderResizeCenterWindow; 2 Ext.EventManager.onWindowResize(function() { 3 if (HotalOrderResizeCenterWindow) { 4 HotalOrderResizeCenter

jQuery如何判断和设定单选多选是否选中??

  如何判断HTML中的单选多选是否选中呢?  这是web编程中最常用的判断,可是前段时间,却遇到了一个很奇怪的问题. 我想很多人会这样判断 if($("#weixuanzhong").attr("checked")=="checked")//选中时 { } 但如果是如下的HTML代码: <input type="checkbox" checked="checked" value="male