Yii Framework Forum: ajaxLink in jsTree not working - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ajaxLink in jsTree not working Rate Topic: -----

#1 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 26 October 2011 - 12:15 PM

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";
}

}

Hey Ho !
Let's go !
0

#2 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 26 October 2011 - 04:51 PM

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.
Hey Ho !
Let's go !
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users