【问题标题】:I want to add css to a node that i am reading node's information我想将 css 添加到我正在读取节点信息的节点
【发布时间】:2014-03-01 11:56:30
【问题描述】:

我在 Yii 框架中使用了 CTreeView,因为我想显示一个用户列表。 所有用户都显示在我的树中,但我想将 css 添加到我正在读取节点信息的节点中。
例如:如果我转到用户/视图/[id],所有用户都会显示树而 [id] 的用户是突出显示的 怎么办?

控制器:

 public function actionAjaxFillTree()
{
    // accept only AJAX request (comment this when debugging)
    if (!Yii::app()->request->isAjaxRequest) {
        exit();
    }
    // parse the user input
    $parentId = Yii::app()->user->id;
    if (isset($_GET['root']) && $_GET['root'] !== 'source') {
        $parentId = (int) $_GET['root'];
    }
    // read the data (this could be in a model)
    $children = Yii::app()->db->createCommand(
        "SELECT m1.id, m1.username AS text, m2.id IS NOT NULL AS hasChildren "
        . "FROM psh_users AS m1 LEFT JOIN psh_users AS m2 ON m1.id=m2.parent_id "
        . "WHERE m1.parent_id <=> $parentId "
        . "GROUP BY m1.id ORDER BY m1.username ASC"
    )->queryAll();

    echo str_replace(
        '"hasChildren":"0"',
        '"hasChildren":false',
        CTreeView::saveDataAsJson($children)
    );
}  

查看:

<?php
$this->widget(
    'CTreeView',
    array('url' => array('ajaxFillTree'),

        )
);
?>
</div>

【问题讨论】:

  • 阅读是指点击时。对吗?
  • 我不确定,但它可能会有所帮助yiiframework.com/wiki/215/…
  • @kumar_v 不,当我单击任何用户并转到查看页面时,有一个用户列表,在视图(用户详细信息)页面中有一个所有用户的树,但我想显示突出显示这个用户,我不点击节点树,
  • @Rafay Zia Mir ,我认为你的建议很好,谢谢,如果我得到好的结果,我就离开这里解决

标签: css ajax yii tree widget


【解决方案1】:

我可以突出显示相关页面的节点:

 public function actionAjaxFillTree() {
    // accept only AJAX request (comment this when debugging)
    if (!Yii::app()->request->isAjaxRequest) {
        exit();
    }
    $node = $_GET[id];
    // parse the user input

    $parentId = Yii::app()->user->id;
    if (isset($_GET['root']) && $_GET['root'] !== 'source') {
        $parentId = (int) $_GET['root'];
    }
    // read the data (this could be in a model)
    $children = Yii::app()->db->createCommand(
                    "SELECT m1.id, m1.username AS text, m2.id IS NOT NULL AS hasChildren "
                    . "FROM psh_users AS m1 LEFT JOIN psh_users AS m2 ON m1.id=m2.parent_id "
                    . "WHERE m1.parent_id <=> $parentId "
                    . "GROUP BY m1.id ORDER BY m1.username ASC"
            )->queryAll();
    $treedata = array();
    foreach ($children as $child) {
        $options =  ($child['id'] == $node)? array('href' => '#', 'id' => $child['id'], 'class' => 'treenode selected_node'):
        array('href' => '#', 'id' => $child['id'], 'class' => 'treenode');
        $nodeText = CHtml::openTag('a', $options);
        $nodeText.= $child['text'];
        $nodeText.= CHtml::closeTag('a') . "\n";
        $child['text'] = $nodeText;
        $treedata[] = $child;
    }
    echo str_replace(
            '"hasChildren":"0"', '"hasChildren":false', CTreeView::saveDataAsJson(**$treedata**)
    );
}

【讨论】:

    猜你喜欢
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    相关资源
    最近更新 更多