标签:
jquery easyui树的简答构造:
JSP页面
组织机构: <input id="p_organId" name="p_organId" style="width: 160px;height: 28px;">
function loadOrgan(){ organ_combotree = $("#p_organId").combotree({ url:'${ctxFront}/cust/tree', multiple:false,//是否可多选 editable:false,//是否可编辑 required:false }); }
后台代码:
/** * easyui树形节点TreeNode模型. * * @author : 尔演&Eryan eryanwcp@gmail.com * @date : 2013-1-11 下午10:01:30 */ @SuppressWarnings("serial") public class TreeNode implements Serializable { /** * 静态变量 展开节点 */ public static final String STATE_OPEN = "open"; /** * 静态变量 关闭节点 */ public static final String STATE_CLOASED = "closed"; /** * 节点id */ private String id; /** * 父级节点id (用于zTree简单数据模型) */ private String pId; /** * 树节点名称 */ private String text; /** * 前面的小图标样式 */ private String iconCls = ""; /** * 是否勾选状态(默认:否false) */ private Boolean checked = false; /** * 自定义属性 */ private Map<String, Object> attributes = Maps.newHashMap(); /** * 子节点 */ private List<TreeNode> children; /** * 是否展开 (open,closed)-(默认值:open) */ private String state = STATE_OPEN; public TreeNode() { this(null, null, ""); } /** * * @param id * 节点id * @param text * 树节点名称 */ public TreeNode(String id, String text) { this(id, text, ""); } /** * * @param id * 节点id * @param text * 树节点名称 * @param iconCls * 图标样式 */ public TreeNode(String id, String text, String iconCls) { this(id, text, STATE_OPEN, iconCls); } /** * * @param id * 节点id * @param text * 树节点名称 * @param state * 是否展开 * @param iconCls * 图标样式 */ public TreeNode(String id, String text, String state, String iconCls) { this.id = id; this.text = text; this.state = state; this.iconCls = iconCls; this.children = Lists.newArrayList(); } /** * * @param id * 节点id * @param text * 树节点名称 * @param iconCls * 图标样式 * @param checked * 是否勾选状态(默认:否) * @param attributes * 自定义属性 * @param children * 子节点 * @param state * 是否展开 */ public TreeNode(String id, String text, String iconCls, Boolean checked, Map<String, Object> attributes, List<TreeNode> children, String state) { super(); this.id = id; this.text = text; this.iconCls = iconCls; this.checked = checked; this.attributes = attributes; this.children = children; this.state = state; } /** * 添加子节点. * * @param childNode * 子节点 */ public TreeNode addChild(TreeNode childNode) { this.children.add(childNode); return this; } /** * 节点id */ public String getId() { return id; } public TreeNode setId(String id) { this.id = id; return this; } /** * 父级节点id (用于zTree简单数据模型) * @return */ public String getpId() { return pId; } /** * @param pId 父级节点id (用于zTree简单数据模型) * @return */ public TreeNode setpId(String pId) { this.pId = pId; return this; } /** * 树节点名称 */ public String getText() { return text; } public TreeNode setText(String text) { this.text = text; return this; } /** * 是否勾选状态(默认:否) */ public Boolean getChecked() { return checked; } public TreeNode setChecked(Boolean checked) { this.checked = checked; return this; } /** * 自定义属性 */ public Map<String, Object> getAttributes() { return attributes; } public TreeNode setAttributes(Map<String, Object> attributes) { this.attributes = attributes; return this; } /** * 子节点 */ public List<TreeNode> getChildren() { return children; } public TreeNode setChildren(List<TreeNode> children) { this.children = children; return this; } /** * 是否展开 */ public String getState() { return state; } public TreeNode setState(String state) { this.state = state; return this; } /** * 图标样式 */ public String getIconCls() { return iconCls; } public TreeNode setIconCls(String iconCls) { this.iconCls = iconCls; return this; } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } }
@RequestMapping(value = {"tree"}) @ResponseBody @DataSource(AppConstants.DATASOURCE_DW)//切换到datasource数据源 public List<TreeNode> tree() throws Exception { List<TreeNode> treeNodes = Lists.newArrayList(); TreeNode proNode = new TreeNode("113600","江西省"); proNode.setChecked(false); proNode.setIconCls("icon-organ-root"); proNode.setpId(null); proNode.setState("closed"); List<Map> citylist=custService.findBySql("select distinct city_id,city_name from dim_organ_sale_procityxian where pro_id='113600' order by city_id", new Parameter()); List<TreeNode> citytree = Lists.newArrayList(); for(Map cityMap :citylist){ TreeNode cityNode = new TreeNode((String)cityMap.get("CITY_ID"),(String)cityMap.get("CITY_NAME")); cityNode.setChecked(false); cityNode.setIconCls("icon-organ-root"); cityNode.setpId(null); cityNode.setState("closed"); List<Map> xialist=custService.findBySql("select distinct xia_id,xia_name from dim_organ_sale_procityxian where city_id='"+cityMap.get("CITY_ID")+"' order by xia_id", new Parameter()); List<TreeNode> xiatree = Lists.newArrayList(); for(Map xiaMap :xialist){ TreeNode xiaNode = new TreeNode((String)xiaMap.get("XIA_ID"),(String)xiaMap.get("XIA_NAME")); xiaNode.setChecked(false); xiaNode.setIconCls("icon-organ-root"); xiaNode.setpId(null); xiaNode.setState("open"); xiatree.add(xiaNode); } cityNode.setChildren(xiatree); citytree.add(cityNode); } proNode.setChildren(citytree); treeNodes.add(proNode); return treeNodes; }
[ { "id" : "113600", "pId" : null, "text" : "江西省", "iconCls" : "icon-organ-root", "checked" : false, "attributes" : { }, "children" : [ { "id" : "113601", "pId" : null, "text" : "南昌市", "iconCls" : "icon-organ-root", "checked" : false, "attributes" : { }, "children" : [ { "id" : "11360102", "pId" : null, "text" : "南昌县", "iconCls" : "icon-organ-root", "checked" : false, "attributes" : { }, "children" : [ ], "state" : "open" }], "state" : "closed" }, "state" : "closed" } ]
动态生成js全局变量:
由于android项目中要不同Tab页进行分页,需要根据栏目的数量动态生成页码page变量存放页码。
for(var i = 0; i < 4; i++) { window["page" + i] = 1; }
在后面的使用中可以用使用,或者用window["page" + i] 当变量用。比如累加:window["page" + i] ++;或者赋值var page=window["page" + i]
版权声明:本文为博主原创文章,未经博主允许不得转载。
jquery easyui树的简答构造+动态生成js全局变量
标签:
原文地址:http://blog.csdn.net/x2145637/article/details/47343541