VISJS 网络图 - Ajax

VISJS Network Graph - Ajax

我的应用程序是 MVC 5。我正在使用 Ajax 使用以下内容填充 vis 网络图节点: 控制器:

 public async Task<JsonResult> GetLinkAnalysis()
        {
            object grid = null;
            grid = await db.OrgChartShape.Where(c=>c.ClusterId != null).Select(c => new
                {
                    id = c.ClusterId,
                    label = c.ClusterId,
                    group = "icons",
                    title = c.FirstName + " " + c.LastName
            }).ToListAsync();
            var result = new
            {
                Grid = grid
            };
            return Json(result, JsonRequestBehavior.AllowGet);
        }

我得到这个结果:

Ajax:

var nodes = [];
   $.ajax({
        type: "GET",
        url: '@Url.Action("GetLinkAnalysis", "Nurse")',
        dataType: "json",
       
        success: function (result) {
            if (result && result.Grid.length > 0) {
                for (var i = 0; i < result.Grid.length; i++) {
                    nodes.push({
                         id: parseInt( result.Grid[i].id),
                        label: result.Grid[i].label,
                        group: result.Grid[i].group,
                        title: result.Grid[i].title,
                        font: { face: "Monospace", align: "center" }
                        });
                }}},
        error: function (err) {alert(err.status + " : " + err.statusText);}
    });

如果我硬编码节点值:

var nodes = [
        { id: 0, label: "0", group: "source" },
        { id: 1, label: "Walter", font: { face: "Monospace", align: "center" }, group: "icons", title: "I have a popup!" },
        { id: 2, label: "2", group: "icons" } 
    ];

有效。

我需要添加 async: false。现在可以使用了。