CTreeView中的CHECKBOX

时间:2013-07-16 02:03:54

标签: yii

有谁知道如何在CTree中放置复选框?我已经拥有treeview,但我不知道如何在其上添加复选框并return 0 || 1结果..请帮助..谢谢..

array("id"=>1,"name"=>"<b>SALES</b>","parents"=>
    array(
        array("id"=>10,"name"=>"<b>Sales Order</b>","parents"=>
            array(
                array("id"=>100,"name"=>"Allow view Transaction PO",
                      array('text' => CHtml::checkBox('name', true)),"parents"

                ),
                array("id"=>101,"name"=>"Allow Click Edit Button PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click New Button PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click Save Button PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click Change Document# PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click Delete Button PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click Print Button PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click Lock Button PO","parents"

                ),
                array("id"=>101,"name"=>"Allow Click Unlock Button PO","parents"

                ),
                array("id"=>101,"name"=>"Un Allow Change Amount PO","parents"

                ),
            ),
        ),
    ),
)

2 个答案:

答案 0 :(得分:3)

在text属性中为每个元素尝试一个复选框:

array(
     ...,
    'text' => CHtml::checkBox('name', true|false) .... 
)

答案 1 :(得分:3)

尝试使用dynatree
为树创建新函数:mytree()

$(function () {
    $("#tree2").dynatree({
        checkbox: true,
        selectMode: 2,
        children: <?php echo json_encode(Department::model()->mytree(75))?>,
        onSelect: function (select, node) {
            // Display list of selected nodes
            var selNodes = node.tree.getSelectedNodes();
            // convert to title/key array
            var selKeys = $.map(selNodes, function (node) {
                return node.data.ID;
            });
            $("#echoSelection2").text(selKeys.join(", "));
            // $("#departments").val(selKeys.join(", "));
        },
        onClick: function (node, event) {
            // We should not toggle, if target was "checkbox", because this
            // would result in double-toggle (i.e. no toggle)
            if (node.getEventTargetType(event) == "title")
                node.toggleSelect();
        },
        onKeydown: function (node, event) {
            if (event.which == 32) {
                node.toggleSelect();
                return false;
            }
        },
    }
}

Html代码

<div id="tree2" style="max-height: 250px;max-width:300px;overflow:scroll; " class="noshowchecktree controls "></div>


结果:
enter image description here