easyUI tree 和构造tree 后台是一样的。
来源:互联网 发布:php前景 知乎 编辑:程序博客网 时间:2024/04/28 14:53
loadproductTree();
initForSearch();
});
// ///////////////////初始化树///////////////////////////////////////////////////////
function loadproductTree() {
$('#productTree')
.tree(
{
checkbox : false,
lines : true,
method : 'post',
url : 'platform/cmtModuleManager/CmtProductWHController/findChildsByNodeId.json',
dataType : "json",
loadFilter : function(data) {
if (data.data) {
return data.data;
} else {
return data;
}
},
onClick : function(node) {
nodeType=node.attributes.NODE_TYPE;
loadproductdimensionality(node.id);
$("#search_CURRENT_NODE_ID").val(currentNodeId);
if(node.attributes.P_ID=="-1"){
$("#toolbarhide").hide();
}else{
$("#toolbarhide").show();
}
},
onLoadSuccess : function(node){
var root = $('#productTree').tree('getRoot');
if(null!=root){
$('#productTree').tree('select',root.target);
currentNodeId=root.id;
loadproductdimensionality(root.id);
$("#search_CURRENT_NODE_ID").val(currentNodeId);
}
$("#toolbarhide").hide();
},
onContextMenu : function(e, node) {
e.preventDefault();
$(this).tree('select', node.target);
if(node.attributes.P_ID=="-1"){
$('#demoMenuRoot').menu('show', {
left : e.pageX,
top : e.pageY
});
}else{
$('#demoMenu').menu('show', {
left : e.pageX,
top : e.pageY
});
}
}
});
}
// //////////////////加载treeGrid树数据/////////////////////////////////////////////////////
/**
* 查询
*/
function initForSearch() {
$('#formSearch')
.searchbox(
{
width : 200,
searcher : function(value) {
var path = "platform/cmtModuleManager/CmtProductWHController/searchTree";
if (value == null || value == "") {
path = "platform/cmtModuleManager/CmtProductWHController/findChildsByNodeId";
}
$.ajax({
cache : true,
type : "POST",
url : path,
dataType : "json",
data : {
search_productName : value
},
async : false,
timeout : 10000,
error : function(request) {
alert("操作失败,服务请求状态:" + request.status + " "
+ request.statusText
+ " 请检查服务是否可用!");
},
success : function(data) {
if (data.result == 0) {
$('#productTree').tree('loadData',
data.data);
} else {
alert("查询失败:" + data.msg);
}
}
});
},
prompt : "请输入关键字!"
});
}
---------------------------------查询后台
/**
* 查询树
* @param response
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "/searchTree")
public ModelAndView searchTree(HttpServletResponse response, HttpServletRequest request)
throws Exception {
ModelAndView mv = new ModelAndView();
TreeNode rootTreeNode=null;
try{
//获取查询参数
Map<String,Object> params=WebUtils.getParametersStartingWith(request,"search_");
List<TreeNode> nodeList=new ArrayList<TreeNode>();
//处理真实查到数据,高亮节点【高亮其实也可以放到前台js去画】
List<CmtProduct> dtList=(List<CmtProduct>)cmtProductWHService.findProductTree(params);
for(CmtProduct dt:dtList){
TreeNode node=new TreeNode();
node.setId(dt.getId());
node.setText("<a style='color:#fff;font-weight:normal;background:#3399ff;padding:0 4px;'>"+dt.getProductName()+"</a>");
node.setState("open");
String nodeType = dt.getNodeType();
String iconCls = cmtProductWHService.setProductIcon(nodeType);
if(dt.getParentId().equals("-1")){
iconCls="nodeType00";
}
node.setIconCls("tree-"+iconCls);
node.setAttributes(dt);
node.set_parentId(dt.getParentId());
nodeList.add(node);
}
//处理父节
List<CmtProduct> pathList=(List<CmtProduct>)cmtProductWHService.findPathDemoTree(dtList);
for(CmtProduct dt:pathList){
TreeNode node=new TreeNode();
node.setId(dt.getId());
node.setText(dt.getProductName());
String nodeType = dt.getNodeType();
String iconCls = cmtProductWHService.setProductIcon(nodeType);
if(dt.getParentId().equals("-1")){
iconCls="nodeType00";
}
node.setIconCls("tree-"+iconCls);
node.setState("open");
node.setAttributes(dt);
node.set_parentId(dt.getParentId());
nodeList.add(node);
}
//转换成具有父子关系的结构
rootTreeNode=TreeUtils.parseToTree(nodeList);
mv.addObject("result",OpResult.success.ordinal());
}catch(Exception e){
logger.error(e.getMessage(),e);
mv.addObject("result",OpResult.failure.ordinal());
mv.addObject("msg","后台处理异常,请联系管理员!");
}
if(rootTreeNode==null){
CmtProduct dt = this.cmtProductWHService.getRootCmtProductTree();
rootTreeNode = new TreeNode();
rootTreeNode.setId(dt.getId());
rootTreeNode.setText(dt.getProductName());
rootTreeNode.setIconCls("tree-nodeType00");
rootTreeNode.setState("open");
rootTreeNode.setAttributes(dt);
rootTreeNode.set_parentId(dt.getParentId());
mv.addObject("data",new Object[]{rootTreeNode});
}else{
mv.addObject("data",new Object[]{rootTreeNode});
}
return mv;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* 查询数据
*/
public List<?> findProductTree(Map<String, Object> params) {
DetachedCriteria dc = DetachedCriteria.forClass(CmtProduct.class);
for (String key : params.keySet()) {
Criterion c = Restrictions.like(key, "%" + params.get(key) + "%");
dc.add(c);
}
List<CmtProduct> treeList = (List<CmtProduct>) this.hibernateDao
.findByCriteria(dc);
return treeList;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* 查询节点的所有父新节点
*
* @param dtList
* 当前节点
* @return 所有当前节点父节点集合
*/
public List<?> findPathDemoTree(List<CmtProduct> dtList) {
List<CmtProduct> treeList = new ArrayList<CmtProduct>();
List<String> pathList = new ArrayList<String>();
// 查询父节点
for (CmtProduct dt : dtList) {
// String path=dt.getPath();
String path = dt.getAttribute01();
if (StringUtils.isEmpty(path))
continue;
List<String> templist = new ArrayList<String>(Arrays.asList(path
.split("\\[&]")));
templist.removeAll(pathList);
pathList.addAll(templist);
}
if (pathList.size() > 0) {
// 防止重复查询
for (CmtProduct dt : dtList) {
if (pathList.contains(dt.getId())) {
pathList.remove(dt.getId());
}
}
if (pathList.size() > 0) {
DetachedCriteria dc2 = DetachedCriteria
.forClass(CmtProduct.class);
Criterion c = Restrictions.in("id", pathList);
dc2.add(c);
List<CmtProduct> dtList2 = (List<CmtProduct>) this.hibernateDao
.findByCriteria(dc2);
treeList.addAll(dtList2);
}
}
return treeList;
}
- easyUI tree 和构造tree 后台是一样的。
- java后台构造easyui的tree数据的一种方法
- ## easyui tree 构造##
- easyUI构造满足tree要求的json
- easyui tree 的异步加载 前台的编写方法和后台的json数据格式组装方法
- Easyui tree 节点的增删改以及同后台交互
- easyui Tree的使用
- easyUI的tree
- EasyUI的中Tree
- easyui tree 的使用
- easyUI tree 的实现
- EasyUI--tree的实现
- Easyui的简单tree
- jquery easyui tree后台组装json
- easyui 扩展 之 Tree的simpleData加载/修改tree数据格式,不一定非是text
- easyui服务器端对树的构造,即easyui tree响应数据格式
- 1020. Tree Traversals (25)多权最短路,和单权是一样的
- easyui ---tree
- bug解决记录——2014/6/6
- 浅析中小型电商邮件营销策略
- JAVA中IO流简介及子类体系
- Database mail issue "Message: The read on the database failed"
- 橱窗位作用
- easyUI tree 和构造tree 后台是一样的。
- 对于结构体变量赋值的误区
- boost.asio的跨平台实现 <转>
- VC++添加菜单栏
- HDU 1253 胜利大逃亡
- linux常用命令详解
- Java 调用 C/C++ 之 JNA 系列实战篇 —— 输入wchar_t* (二)
- Connection Reset By Peer 解析
- 文件下载servlet