zoukankan      html  css  js  c++  java
  • thinkphp关联查询实现动态加载easyUI组合树ComboTree

    easyUI官方组合树ComboTree代码:

    1.                             
      1. !DOCTYPE html>
      2. <html>
      3. <head>
      4. <meta charset="UTF-8">
      5. <title>Basic ComboTree - jQuery EasyUI Demo</title>
      6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
      7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
      8. <link rel="stylesheet" type="text/css" href="../demo.css">
      9. <script type="text/javascript" src="../../jquery.min.js"></script>
      10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
      11. </head>
      12. <body>
      13. <h2>Basic ComboTree</h2>
      14. <p>Click the right arrow button to show the tree panel.</p>
      15. <div style="margin:20px 0"></div>
      16. <input class="easyui-combotree" data-options="url:'tree_data1.json',method:'get',required:true" style="width:200px;">
      17.  
      18. </body>
      19. </html>

    tree_data1.json:

    [{
    	"id":1,
    	"text":"My Documents",
    	"children":[{
    		"id":11,
    		"text":"Photos",
    		"state":"closed",
    		"children":[{
    			"id":111,
    			"text":"Friend"
    		},{
    			"id":112,
    			"text":"Wife"
    		},{
    			"id":113,
    			"text":"Company"
    		}]
    	},{
    		"id":12,
    		"text":"Program Files",
    		"children":[{
    			"id":121,
    			"text":"Intel"
    		},{
    			"id":122,
    			"text":"Java",
    			"attributes":{
    				"p1":"Custom Attribute1",
    				"p2":"Custom Attribute2"
    			}
    		},{
    			"id":123,
    			"text":"Microsoft Office"
    		},{
    			"id":124,
    			"text":"Games",
    			"checked":true
    		}]
    	},{
    		"id":13,
    		"text":"index.html"
    	},{
    		"id":14,
    		"text":"about.html"
    	},{
    		"id":15,
    		"text":"welcome.html"
    	}]
    }]

    思路:想要实现动态加载,必须从数据库返回具有父子层级关系的数据格式,(涉及到三级菜单以上的话要使用多级关联查询,)才能正确显示。

    数据表Xzq:id,name,parentId  (菜单为自关联)

          1,中国,0  

          2,安徽,1

          3,浙江,1

    Thinkphp代码实现:

    模型层:

      <?php
    namespace HomeModel;
    use ThinkModelRelationModel;
    class XzqModel extends RelationModel{
        protected $_link = array(
            'children' =>array(
                'mapping_type'  => self::HAS_MANY,         //关联关系
                'class_name'    => 'Category',          //要关联的模型类名
                'parent_key'   => 'parentId',          //自引用关联的关联字段
                'mapping_fields'=>'id,name as text,parentId',   //关联要查询的字段
                'relation_deep'=>true,               //支持多级查询设置
            )
        );

     控制器:

       $result=$category->field('id,name as text')->relation(true)
           ->where('companyUserId='.session('id').' and parentId=0')->select();

    这样得到的关联数组即是一个符合easyUI组合树ComboTree要求的数据格式。

  • 相关阅读:
    一些使用Android设备调试功能的注意事项(挖职位)
    Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; neste
    HIbernate java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z
    applicationContext.xml 配置
    No setter found for property 'userDAO' in class 'com.ssh.service.impl.User1Service'
    structs 源码示例
    基于MyEclipse+9.0+++Tomcat+7.0的SSH+平台搭建
    struts2错误:The Struts dispatcher cannot be found.
    使用Struts2开发Java Web应用程序(目录)
    MyEclipse中导入Spring 4.0源码
  • 原文地址:https://www.cnblogs.com/ahguSH/p/5093432.html
Copyright © 2011-2022 走看看