Miniui 二级树简单实例

原创
2016/11/15 10:04
阅读数 1.3K

miniui 前台树控件写法(绑定后台实体类中资格序列的字段)

前台javascript中初始化加载后台,通过bind来绑定dataBean

    <div role="row">

                                <div role="control" label="资格序列" starred="true">

                                    <input class="mini-treeselect" action="getTreeModel" showRadioButton="true" showFolderCheckBox="false" bind="dataBean.zigexulie" id="TreeModel" multiSelect="false" />

                                </div>

                            </div>  

 

树控件模型后台写法(Java)

 /**

     * 树控件模型

     */

    private TreeModel treeModel;

 

 public TreeModel getTreeModel() {

        if (treeModel == null) {

            treeModel = new TreeModel()

            {

                private static final long serialVersionUID = 1L;

                @Override

                public List<TreeNode> fetch(TreeNode node) {

                   //定义一个arraylist集合

                    List<TreeNode> nodes = new ArrayList<>();

                    if (node == null) {

                        List<Record> lst = service.findList(

                                "select item_text,item_code from CG_Ry_ZiZhi_Basic where length(item_code)=2",

                                Record.class);

                        for (Record i : lst) {

                            TreeNode tn = new TreeNode();

                            tn.setId(i.getStr("item_code"));

                            tn.setText(i.getStr("item_text"));

                            //控制父节点下若是没有子节点设置单选

                            String code=i.getStr("item_code");

                            String sql="select count(1) from CG_Ry_ZiZhi_Basic where item_code like '"+code+"__'";

                            int num=service.queryInt(sql);

                            if(num==0){

                                tn.setLeaf(true);

                            }else{

                                tn.setLeaf(false);

                            }

                            nodes.add(tn);

                        }

                        return nodes;

                    }

                    else {

                        List<Record> lst = service

                                .findList("select item_text,item_code from CG_Ry_ZiZhi_Basic where item_code like '"

                                        + node.getId() + "__'", Record.class);

                        for (Record i : lst) {

                            TreeNode tn = new TreeNode();

                            tn.setId(i.getStr("item_code"));

                            tn.setText(i.getStr("item_text"));

                            tn.setPid(node.getId());

                            tn.setLeaf(true);

                            nodes.add(tn);

                        }

                        return nodes;

                    }

                }

            };

        }

        return treeModel;

    }

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部