CjsTree with initially_select

Hello,

I have created a jsTree, but I need to start selecting a particular node. Reading the jsTree documentation initially_select should be done, but it not works. Does anyone know how?




		<?php $this->widget('application.extensions.jsTree.CjsTree', array(

			'id'=>'secondTree',

			'selected'=>$model->ubic_id,

			'ui'=>array(

				'selected_parent_close'=>'select_parent',

				'selected_parent_open'=>'true',

				'initially_select'=>array($model->ubic_id),

			),

			'data' => array(

			    'type' => 'json',

			    'async'=> true,

			    'opts' => array(

				'method'=>'GET',

				'async'=>true,

				'url' => $this->createUrl('ubic/render'),

			      

			    ),


			),

			'callback'=>array(

			    //'beforedata'=>'js: function(NODE, TREE_OBJ) { return { id : $(NODE).attr("id") || '.$model->ubic_id.'}; }', // 0 means its the first time to render the tree

			    'beforedata'=>'js: function(NODE, TREE_OBJ) { return { id : $(NODE).attr("id") || 0 }; }', // 0 means its the first time to render the tree

			    'onselect'=>'js:function(NODE, TREE_OBJ) {

				alert("Ubicacion seleccionada:"+TREE_OBJ.get_text(NODE));

				jQuery("#Stocks_ubic_id").val(NODE.id);

			    }',

			),

		    ));

		?>



I got it, this is my solution:




	<?php 

		$ancestros=Ubic::model()->getAncestros2($model->ubic_id);

	?>

        <?php $this->widget('application.extensions.jsTree.CjsTree', array(

        'id'=>'secondTree',

			'selected'=>$model->ubic_id,

			'opened'=>$ancestros,

			'ui'=>array(

				'theme_name'=>'apple',

				'selected_parent_close'=>'select_parent',

			),

			'data' => array(

			    'type' => 'json',

			    'async'=> true,

			    'opts' => array(

				'method'=>'GET',

				'async'=>true,

				'url' => $this->createUrl('ubic/render'),

			      

			    ),


			),

			'callback'=>array(

			    //'beforedata'=>'js: function(NODE, TREE_OBJ) { return { id : $(NODE).attr("id") || '.$model->ubic_id.'}; }', // 0 means its the first time to render the tree

			    'beforedata'=>'js: function(NODE, TREE_OBJ) { return { id : $(NODE).attr("id") || 0 }; }', // 0 means its the first time to render the tree

			    'onselect'=>'js:function(NODE, TREE_OBJ) {

				jQuery("#Stocks_ubic_id").val(NODE.id);

			    }',

	),

));

?>



And in model:




	public function getAncestros2($id=1) {

		$itemsFormatted = array();

		$ubi=Ubic::model()->findByPK($id);

		$criteria=new CDbCriteria;

		$criteria->mergeWith(array(

			'condition'=>"lft<=:izq AND rgt>=:der",

			'order'=>"lft ASC",

			'params'=>array(':izq'=>$ubi->lft, ':der'=>$ubi->rgt),	

		));

		$ancestros=Ubic::model()->findAll($criteria);

		foreach ($ancestros as $item) {

			$itemsFormatted[$item->id]=$item->id;

		}

		return $itemsFormatted;

	}