0

嗨,我正在尝试修改 jsGrid 演示中的“DataManipulation”示例,但无法显示使用 GET ajax 调用检索的 json 文件中的数据。这是我的控制器代码:

{
                loadData: function (filter) {
                    var data = $.Deferred();
                $.ajax({
                   type: "GET",
                   contentType: "application/json",
                   url: "myFileURL.json",

                   dataType: "json"
                   }).done(function(response){
                     console.log(response);
                     data.resolve(response);
                 });
                  return data.promise();}

检索的json是这样的

{"98762":{"Address":"Address 1","Age":1,"Country":1,"Married":false,"Name":"Name1"},"637399":{"Address":"Address 2","Age":2,"Country":2,"Married":true,"Name":"Name 2"},"234567554":{"Address":"Address 3","Age":3,"Country":3,"Married":true,"Name":"Name"}}
4

1 回答 1

1

您的 json 格式不正确。jsGrid 需要一个对象列表作为返回类型。改用这个。

 [
    {
        "Address": "Address 1",
        "Age": 1,
        "Country": 1,
        "Married": false,
        "Name": "Name1"
    },
    {
        "Address": "Address 2",
        "Age": 2,
        "Country": 2,
        "Married": true,
        "Name": "Name 2"
    },
    {
        "Address": "Address 3",
        "Age": 3,
        "Country": 3,
        "Married": true,
        "Name": "Name"
    }
];

这是假设 json 的模式是正确的。祝你好运!

于 2016-10-18T11:19:30.543 回答