ajaxLink in jsTree not working

Hi yii fans,

I have categories that are order using the nested set behavior. When I use an ajaxLink:


echo CHtml::ajaxLink($category->name,'category/returnSideView', array('update' => '#sideview', 'type' => 'POST','data'=>$category->id));

in a simple list view, my #sideview div is updated.

But when I display the categories in a jsTree view (the ajaxLink are created in the category model), nothing happens especially no action call and no errors …

here’s model function :




  public static  function printULTree(){

     $categories=Category::model()->findAll(array('order'=>'root,lft'));

     $level=0;


foreach($categories as $n=>$category)

{


    if($category->level==$level)

        echo CHtml::closeTag('li')."\n";

    else if($category->level>$level)

        echo CHtml::openTag('ul')."\n";

    else

    {

        echo CHtml::closeTag('li')."\n";


        for($i=$level-$category->level;$i;$i--)

        {

            echo CHtml::closeTag('ul')."\n";

            echo CHtml::closeTag('li')."\n";

        }

    }


    echo CHtml::openTag('li',array('id'=>'node_'.$category->id,'rel'=>$category->name));

      //echo CHtml::openTag('a',array('href'=>'#'));

      echo CHtml::ajaxLink($category->name,'category/returnSideView', array('update' => '#sideview', 'type' => 'POST','data'=>$category->id));

    //echo CHtml::encode($category->name);

      //echo CHtml::closeTag('a');


    $level=$category->level;

}


for($i=$level;$i;$i--)

{

    echo CHtml::closeTag('li')."\n";

    echo CHtml::closeTag('ul')."\n";

}


}

It seems that something must break the CHtml:ajaxLink function in my case.

Is it because ajaxLink is called in the model ? Or because there is a kind trick to make it work with jsTree ? I don’t know.

How to solve that problem:

in my view, where the jsTree is shown, I’ve ad this after the call of jsTree:




.bind("select_node.jstree", function (e, data) { 

				$.ajax({

				async : false,

				type: 'GET',

				url: "category/returnSideView",


				data : {

					"id" : data.rslt.obj.attr("id"),

				         "YII_CSRF_TOKEN":"<?php echo Yii::app()->request->csrfToken;?>"

                                          },

                                update : "#sideview",


			}); //ajax

})

No more use of ajaxLink in the model with that trick. But don’t forget to load the “ui” jsTree plugin and in the returnSideView action, I have to use php’s substr() function to get the real id, because the id GET parameter looks like “node_4” where 4 is the real id.

Hope this help.