Miniui 二級樹簡單實例

miniui 前臺樹控件寫法(綁定後臺實體類中資格序列的字段)javascript

前臺javascript中初始化加載後臺,經過bind來綁定dataBeanjava

    <div role="row">node

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

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

                                </div>fetch

                            </div>  ui

 

樹控件模型後臺寫法(Java)spa

 /**code

     * 樹控件模型ip

     */

    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;

    }

相關文章
相關標籤/搜索