效果图:

C#树状图 初始默认选中节点_javascript

<script type="text/javascript">
    $(document).ready(function () {
        GetTree();
        GetGrid();
        //默认选中按钮,记得将字段中的—转换为_
        $("#ItemsTree_" + '@ViewBag.CompanyId'.replace(/\-/g, '_')).addClass("bbit-tree-selected");
    });
    var CompanyId = '@ViewBag.CompanyId', CompanyName = "";
    //加载左边树
    function GetTree() {
        var itemtree = {
            onnodeclick: function (item) {
                CompanyId = item.id;            //ID
                CompanyName = item.text;        //名称
                $("#CenterTitle").html(" - " + CompanyName);
                $("#gridTable").jqGrid('setGridParam', {
                    url: "@Url.Content("~/System/Roles/GridPageListJson")?CompanyId=" + CompanyId, page: 1
                }).trigger('reloadGrid');
            },
            url: "@Url.Content("~/System/School/TreeJson")"
        };
        $("#ItemsTree").treeview(itemtree);
    }