1 首先在前端应用树树控件

<div class="fui-left">
<div role="head" title="地区选择"></div>
<div role="body">
<div id="key" class="mini-textbox hidden" style="width: 150px;" onenter="onKeyEnter" />
<div class="mini-button hidden" style="width: 50px;" onclick="search()">查询</div>
<div id="tree1" class="mini-tree" showFolderCheckBox="true" action="treeModel" canCheckParent="true"></div>
</div>
</div>

2 在后台要有一个变量与之对应

private TreeModel treeModel = null;

3 这个变量的get方法来获得数据

public TreeModel getTreeModel() {
if (treeModel == null) {
treeModel = new TreeModel()
{
private static final long serialVersionUID = 1L; @Override
public List<TreeNode> fetch(TreeNode pNode) {
List<Record> tmplist;
String guid = "";
if (pNode != null)
guid = pNode.getId(); // 根节点
if (StringUtil.isBlank(guid)) { tmplist = service.findList(
"select CityName,CityCode from HuiYuan_City where right(CityCode,4)='0000' order by CityCode ",
Record.class); }
else {
guid = Functions.TrimEnd(guid, "0");
String sql = "";
if (guid.length() == 2) {
sql = "select CityName,CityCode from HuiYuan_City where citycode like '" + guid
+ "%' and right(CityCode,2)='00' and right(CityCode,4)<>'0000' order by CityCode";
}
else if (guid.length() == 4) {
sql = "select CityName,CityCode from HuiYuan_City where citycode like '" + guid
+ "%' and right(CityCode,2)<>'00' order by CityCode";
}
tmplist = service.findList(sql, Record.class);
} List<TreeNode> treeNodes = new ArrayList<TreeNode>(); //修改在省级子节点中出现"所有地区"节点的问题 by dingbq 2016-8-29
if(StringUtil.isBlank(guid)){
TreeNode node1 = new TreeNode();
node1.setId("999");
node1.setText("所有地区");
node1.setLeaf(false);
node1.setExpanded(true);
treeNodes.add(node1);
} for (Record record : tmplist) {
TreeNode node = new TreeNode();
node.setId(record.getStr("CityCode"));
node.setText(record.getStr("CityName"));
String code = node.getId();
if(StringUtil.isBlank(guid)){
node.setPid("999");
}
if (code.endsWith("00"))
node.setLeaf(false);
else
node.setLeaf(true);
treeNodes.add(node);
}
return treeNodes;
} }; }
return treeModel;
}
05-08 15:36