0

Jsonデータとして:

{id: "1", name: "Cash", num: "100", debit: "400.00",  credit: "250.00",
    balance: "150.00", enbl: "1", level: "0", parent: "null",
    isLeaf: false, expanded: true, loaded: true}

パラメータ「expanded」は役に立たないようですか?

JSON データを初期化するときに、すべてのノードまたは特定のノードを展開する方法がわかりません。


Oleg へ: デモをありがとう、でもそのページにアクセスできません! - - !次に、私の JavaScript コードを示します。問題が見つかるかもしれません。

$(function () {
        $('#list').jqGrid({
            url: 'SvcDept.ashx',
            ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
            datatype: 'json',
            mtype: 'GET',
            treeGrid: true,
            treeGridModel: 'adjacency',
            ExpandColumn: 'Name',
            colNames: ['ID', 'Name', 'Director', 'ParentID'],
            colModel: [
            { name: 'ID', index: 'ID', hidden: true, width: 1, key: true },
            { name: 'Name', index: 'Name', width: 200, fixed: true },
            { name: 'Director', index: 'Director', width: 100 },
            { name: 'ParentID', index: 'ParentID', hidden: true, width: 1 }
            ],
            autowidth: true,
            height: 'auto'
        });
    });

および私の SvcDept.ashx:

public class SvcDept 
{
    public void ProcessRequest(HttpContext context)
    {
        var depts = context.Application["Departments"] as List<Department>;
        var nodeid = context.Request["nodeid"];
        var n_level = context.Request["n_level"];
        Guid? deptID = nodeid != null ? new Guid(nodeid) : new Nullable<Guid>();
        int level = n_level != null ? int.Parse(n_level) + 1 : 0;
        var subDepts = depts.Where<Department>(x => x.ParentID == deptID).ToList<Department>();
        var data = new
        {
            page = 1,
            total = 1,
            records = subDepts.Count,
            rows = (from dept in subDepts
                    select new
                    {
                        cell = new[] 
                        {
                            dept.ID.ToString(),     
                            dept.Name,               
                            dept.Director ,
                            dept.ParentID != null ? dept.ParentID.ToString() : "",                                
                            level.ToString(),   //Level
                            deptID != null ? deptID.ToString() : "null",    //ParentID
                            depts.Count<Department>(x => x.ParentID == dept.ID) == 0 ? "true":"false",  //isLeaf
                            "true", //expanded
                            "false"//loaded
                        }
                    })
        };
        context.Response.ContentType = "application/json";
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        context.Response.Write(serializer.Serialize(data));
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
 public class Department
{
    public Guid ID { get; set; }
    public string Name { get; set; }
    public string Director { get; set; }
    public Guid? ParentID { get; set; }
}
4

1 に答える 1