We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39452
    • 11 Posts
    Хочу сделать дерево в компоненте, не получается, дерево пустое
    //x:\home\localhost\www\assets\components\tests\js\mgr\widgets\home.panel.js
    Tests.panel.Home = function(config) {
        config = config || {};
    
    Ext.apply(config,{
            border: false
            ,baseCls: 'modx-formpanel'
            ,items: [
    	        {                    //заголовок
    	            html: '<h2>'+_('tests.management')+'</h2>'
    	            ,border: false
    	            ,cls: 'modx-page-header'
    	        },
    	        {        //враппер
    	        xtype: 'panel'
    	        ,layout: 'hbox'
    	        ,items:
    	           [
    
    
    	           {          //дерево
    	           xtype: 'treepanel',
    	           region: 'west',
    		       width: 200,
    		       autoScroll: true,
    		       split: true,
    		       bodyBorder :false,
    		       hideCollapseTool:true,
    		       rootVisible: true,    /*  */
    
    		        loader: aa=new Ext.tree.TreeLoader({
    						dataUrl: '../core/components/tests/processors/mgr/test/get_tree.php'
    				}),
    				listeners: {
    		            click: function(n) {
    
    		                Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
    		            }
    		        },
    
    				root: new Ext.tree.AsyncTreeNode({
    						expanded: true,
    						text: _('tests'),
    		        		draggable: false,
    		        		id: 'source'
    					 }),
    	        	},
    
    
    
    	            //табы
    	        	{
    	            xtype: 'modx-tabs',
    	            bodyStyle: 'padding: 10px',
    	            defaults: { border: false ,autoHeight: true },
    	            border: true,
    	            items: [{
    	                title: _('tests'),
    	                defaults: { autoHeight: true },
    	                items: [{
    	                    html: '<p>'+_('tests.management_desc')+'</p>
    ',
    	                    border: false
    	                	},
    	                	{
    	                    xtype: 'tests-grid-tests',
    	                    preventRender: true
    	                }]
    	            }]
    	        	}//табы    */
    	            ]
    	          } //враппер
    	     ]
    	    }
      );
    
        Tests.panel.Home.superclass.constructor.call(this,config);
    };
    Ext.extend(Tests.panel.Home,MODx.Panel);
    Ext.reg('tests-panel-home',Tests.panel.Home);
    


    если делаю так - работает
              <?
              //x:\home\localhost\www\core\components\tests\processors\mgr\test\get_tree.php
    
    
       $sampleArr =  array( array( id=>1, 'text'=>"Node 1", leaf=>true),  array( id=>2, 'text'=>"Node 2", leaf=>true )      );
       echo json_encode($sampleArr); 
       return '';


    если так - выводит пустое дерево

    $isLimit = !empty($scriptProperties['limit']);
    $start = $modx->getOption('start',$scriptProperties,0);
    $limit = $modx->getOption('limit',$scriptProperties,20);
    $sort = $modx->getOption('sort',$scriptProperties,'name');
    $dir = $modx->getOption('dir',$scriptProperties,'ASC');
    $query = $modx->getOption('query',$scriptProperties,'');
    
    /* build query */
    
    $c = $modx->newQuery('Test');
    
    if (!empty($query)) {
        $c->where(array(
            'name:LIKE' => '%'.$query.'%',
            'OR:description:LIKE' => '%'.$query.'%',
        ));
    }
    
    $count = $modx->getCount('Test',$c);
    $c->sortby($sort,$dir);
    if ($isLimit) $c->limit($limit,$start);
    $tests = $modx->getIterator('Test', $c);
    
    /* iterate */
    
    $list = array();
    foreach ($tests as $test) {
        $testArray = $test->toArray();
    
        $list[]=array(id=> $testArray['id'], text=> $testArray['name'], leaf=> true,);
    }
    return $this->outputArray($list,$count); 
    
    

    [ed. note: al3x777 last edited this post 14 years, 5 months ago.]
      • 39452
      • 11 Posts
      как посмотреть что выдает?
      loader: aa=new Ext.tree.TreeLoader({
                              dataUrl: '../core/components/tests/processors/mgr/test/get_tree.php'
                      }),
        • 39452
        • 11 Posts
        а-у есть тут кто живой?

        сделал так: создал сниппет с пустым шаблоном

        <?php
        //x:\home\localhost\www\core\components\tests\processors\mgr\test\get_tree.php
        
                $doodles = $modx->getService('tests','Tests',$modx->getOption('tests.core_path',null,$modx->getOption('core_path').'components/tests/').'model/tests/',$scriptProperties);
        if (!($doodles instanceof Tests)) return '';
        
        
        $isLimit = !empty($scriptProperties['limit']);
        $start = $modx->getOption('start',$scriptProperties,0);
        $limit = $modx->getOption('limit',$scriptProperties,20);
        $sort = $modx->getOption('sort',$scriptProperties,'name');
        $dir = $modx->getOption('dir',$scriptProperties,'ASC');
        $query = $modx->getOption('query',$scriptProperties,'');
        
        /* build query */
        
        $c = $modx->newQuery('Test');
        
        if (!empty($query)) {
            $c->where(array(
                'name:LIKE' => '%'.$query.'%',
                'OR:description:LIKE' => '%'.$query.'%',
            ));
        }
        
          $count = $modx->getCount('Test',$c);
        
        $c->sortby($sort,$dir);
        if ($isLimit) $c->limit($limit,$start);
        $tests = $modx->getIterator('Test', $c);
        
        /* iterate */
        
        $list = array();
        foreach ($tests as $test) {
            $testArray = $test->toArray();
        
            $list[]=array(id=> $testArray['id'], text=> $testArray['name'], leaf=> true,);
        }
        
        
          echo json_encode($list);
          return '';
        //echo $this->outputArray($list,$count); return '';
        
        

        работает...
        помогите процессор поправть.
        и еще что то я не понял к какому объекту идет обращение
        return $this->outputArray($list,$count);

        на какой объект указывает this???
        ПС: посоветуйте какаую нибудь среду разработки php/js с хорошим дебаггером, а то я задолбался ошибки вруную отлавливать

        ЗЫЫ: если кто знает как в денвере дебаггер настроить просьба кинуть ссылкой [ed. note: al3x777 last edited this post 14 years, 5 months ago.]