Home > Web Front-end > JS Tutorial > body text

EasyUI implements asynchronous tree in jquery_jquery

WBOY
Release: 2016-05-16 16:12:00
Original
985 people have browsed it

The frontend is implemented using EasyUI. EasyUI passes an id parameter to the backend.

When loading for the first time, the id passed to the background is null.

Every time the tree node is expanded, the id of the current node will be passed to the background.

Control layer:

Copy code The code is as follows:

/**
  * tree
 */
@RequestMapping(value = "/tree.do")
public void mytree(HttpServletResponse response, String id) {
This.writeJson(response, bookService.getChildrenTree(id));
}

Service layer:

Copy code The code is as follows:

@Transactional
@Override
public List getChildrenTree(String pid) {
try {
List result = new ArrayList();
//Get the list of child nodes
List childrenList = this.getChildrenType(pid);
if (childrenList != null && childrenList.size() > 0) {
for (TBookType child : childrenList) {
// Get the number of grandchildren
Long count = bookDao.getChildrenCount(String.valueOf(child.getId()));
Tree node = new Tree();
Node.setId(String.valueOf(child.getId()));
Node.setPid(String.valueOf(child.getPid()));
Node.setText(child.getName());
Node.setChildren(null);
​​ node.setState(count > 0 ? "closed" : "open");
//Save the childrenList data into the tree one by one
result.add(node);
}
}
Return result;
} catch (Exception e) {
throw new BusinessException("An error occurred while obtaining book type data!", e);
}
}

Dao layer:

Copy code The code is as follows:

@Override
public List getChildrenType(String pid) {
//The pid of this is the id of the currently expanded node, and the child node is obtained through the id of the parent node
StringBuilder sqlstr = new StringBuilder();
if (StringUtils.isBlank(pid))
sqlstr.append("select * from booktype bt where bt.pid=0");
else
sqlstr.append("select * from booktype bt where bt.pid=" pid );
Return this.search2(TBookType.class, sqlstr.toString());
}

Copy code The code is as follows:

@Override
public long getChildrenCount(String pid) {
//The pid of this is the id of the currently expanded node, and the number of child nodes is obtained through the id of the parent node
StringBuilder sqlstr = new StringBuilder();
if (StringUtils.isBlank(pid))
sqlstr.append("select count(*) from booktype tb where tb.pid='0'");
else
sqlstr.append("select count(*) from booktype tb where tb.pid='" pid "'");
Return this.count(sqlstr.toString());
}

The above is all the code of this article about EasyUI implementing asynchronous trees. I hope it will be helpful to everyone

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!