描述的比较长请看下去,第一种情况生成的html代码和第二种不一致的,说明参数无效。
list.php这个View嵌入了CTreeView的代码:
<?php$this->widget('CTreeView',array('url'=>array('listTreeData','root'=>$root),'animated'=>'fast','htmlOptions'=>array('class'=>'treeview-red')));
?>
运行的TypeController的代码如下:
public function actionList(){if(isset($_GET['root'])){ $root=$_GET['root']; }else{ $root='source'; } $this->renderPartial('list',array('root'=>$root,),array(),true); }code]
生成的list.php生成的html如下:[code]<ul class="treeview-red" id="yw0">
</ul><script type="text/javascript">
/<![CDATA[/
jQuery(document).ready(function() {
jQuery("#yw0").treeview({'url':'/slp_oa/index.php?r=type/listTreeData&root=9','animated':'fast'});
});
/]]>/
</script>
第一种情况,运行http://localhost/slp_oa/?r=type/list&root=9生成如下html
生成如下代码,已经过滤了html代码:
Quote
文件分类TypeArticle1是添子类 修改 移动 删除
公文分类TypeDocument1是添子类 修改 移动 删除
文件分类TypeFile1是添子类 修改 移动 删除
档案密级分类TypeFileSecret1是添子类 修改 移动 删除
文件紧急程度TypeFileUrgency1是添子类 修改 移动 删除
用工类型TypeLabor1是添子类 修改 移动 删除
在listTreeData中的代码:
public function actionListTreeData(){ if(!isset($_GET['root'])){ $parentId='source'; }else{ $parentId=$_GET['root']; } $dataTree=array(); $userList=array(); if($parentId=='source'){ $typeList=Type::model()->with('children')->findAll('parent_id is null'); }else{ $typeList=Type::model()->with('children')->findAll('parent_id ='.$parentId); } if(is_array($typeList)){ foreach($typeList as $type){ $dataTree[]=$this->formatData($type); } } echo CTreeView::saveDataAsJson($dataTree); } protected function formatData($type){ $text='<div class="x-column-tree">'. '<div class="x-tree-col" style="width:200px;">'.$type['name'].'</div>'. '<div class="x-tree-col" style="width:130px;">'.$type['code'].'</div>'. '<div class="x-tree-col" style="width:30px;">'.$type['priority'].'</div>'. '<div class="x-tree-col" style="width:60px;">'.($type['leaf']==true?'是':'否').'</div>'. '<div class="x-tree-col" style="width:120px;"><a href="?r=type/create">添子类</a>'; if($type['remove']){ $text=$text.' <a href="?r=type/update">修改</a>'; $text=$text.' <a href="?r=type/move">移动</a>'; $text=$text.' <a href="?r=type/delete">删除</a>'; } $text=$text.'</div></div>'; return array('text'=>$text,'id'=>$type['id'],'hasChildren'=>false); }
第二种情况直接运行jruery里面的url:http://localhost/slp_oa/index.php?r=type/listTreeData&root=9生成如下html:
Quote
\u4e2a\u4eba\u6d88\u606f</div>
TypeMessage</div>
1</div>
\u662f</div>
\u6dfb\u5b50\u7c7b</a> \u4fee\u6539</a> \u79fb\u52a8</a> \u5220\u9664</a></div></div>","id":"15","hasChildren":false},{"text":"
\u5de5\u4f5c\u6d41</div>
TypeMessage</div>
1</div>
\u662f</div>
\u6dfb\u5b50\u7c7b</a> \u4fee\u6539</a> \u79fb\u52a8</a> \u5220\u9664</a></div></div>","id":"59","hasChildren":false},{"text":"
\u5185\u90e8\u901a\u77e5</div>
TypeMessage</div>
1</div>
\u662f</div>
\u6dfb\u5b50\u7c7b</a> \u4fee\u6539</a> \u79fb\u52a8</a> \u5220\u9664</a></div></div>","id":"72","hasChildren":false},{"text":"
\u516c\u5171\u901a\u544a</div>
TypeMessage</div>
1</div>
\u662f</div>
\u6dfb\u5b50\u7c7b</a> \u4fee\u6539</a> \u79fb\u52a8</a> \u5220\u9664</a></div></div>","id":"73","hasChildren":false}]
可以从TypeMessage这个字眼看出代码不一致。不知道原因出在哪里?
大概知道情况是如果用嵌入jquery的方式的话,参数无效。直接调用url参数有效。