0

我正在使用 EXT.NET 并且有一个问题。我无法将 json 数据加载到网格面板中。我的代码如下。单击树项时,selectNode 函数会正确触发,但 JSON 结果无法加载到 Grid 面板中。如何加载到网格面板中?目前,弹出白色空白页。

@model System.Collections.IEnumerable

@{
    Layout = null;
    var X = Html.X();
}

<script type="text/javascript">

    var selectNode = function (item, record, node, index, event) {

        Ext.Ajax.request({
            url: "/Popup/GetDepartmentUser",
            method: "POST",
            params: {
                id: record.data.id
            },

            callback: function (options, success, response) {
                if (Ext.decode(response.responseText).success == false) {
                    Ext.Msg.alert("Failed", response.responseText);
                } else {
                    var grid = App.theGrid;

                    grid.show();
                    grid.getStore().loadData(Ext.decode(response.responseText));
                    //Ext.Msg.alert("Success", response.responseText);
                }
            },

            failure: function (response, options) {
                Ext.MessageBox.alert("Failed", response.responseText);
            },

            timeout: '10000'

        });

    }
</script>


<!DOCTYPE html>

<html>
<head>
    <title>Search User</title>
</head>
<body>

    @(Html.X().ResourceManager())

    @(X.Panel()
        .Layout(LayoutType.Border)
        .Width(780)
        .Height(460)
        .Items(
            X.TreePanel()
                .Title("Department")
                .ID("theTree")
                .Region(Region.West)
                .Width(250)
                .Height(460)
                .Border(false)
                .Split(true)
                .UseArrows(true)
                .Listeners(l => l.ItemClick.Fn = "selectNode")
                .Store(
                    Html.X().TreeStore()
                        .Proxy(
                            Html.X().AjaxProxy().Url(Url.Action("GetDepartmentChildren"))
                        )
                )
                .Root(
                    Html.X().Node().NodeID("0").Text(ViewBag.OrganizationName)
                ),


            Html.X().GridPanel()
                .ID("theGrid")
                .Title("User Information")
                .Region(Region.Center)
                .Width(530)
                .Height(460)
                .Border(false)
                .Store(Html.X().Store()
                    .AutoLoad(false)
                    .Model(Html.X().Model()
                        .Fields(
                            new ModelField("FirstName", ModelFieldType.String),
                            new ModelField("LastName", ModelFieldType.String),
                            new ModelField("Email", ModelFieldType.String)
                        )
                    )
            //.DataSource(Model)
                    .Reader(reader => reader.Add(Html.X().JsonReader().Root("data")))
                )

                .ColumnModel(
                    Html.X().Column()
                        .Text("First Name")
                        .DataIndex("FirstName")
                        .Flex(1),
                    Html.X().Column()
                        .Text("LastName")
                        .DataIndex("LastName")
                        .Width(70)
                        .Align(Alignment.Center),
                    Html.X().Column()
                        .Text("Email")
                        .DataIndex("Email")
                        .Width(140)

                )
                .View(Html.X().GridView().StripeRows(true).TrackOver(true))
        )
    )



</body>
</html>

这是 JSON 结果数据

 {
  "success":true,
  "total":2,
  "data":"[
    {
     \"FirstName\":\"BlahBlah1\",
     \"LastName\":\"Kwak\",
     \"Email\":\"BlahBlah1@hotmail.com\"
    },
    {
     \"FirstName\":\"BlahBlah2\",
     \"LastName\":\"Kwak\",
     \"Email\":\"BlahBlah1@hotmail.com\"
    }
  ]"
 }
4

1 回答 1

0

我发现 loadData 方法只读取模型记录数据。

所以,我通过使用 loadRawData 方法而不是 loadData 来修复它。

于 2013-08-13T17:41:02.337 回答