0

I have a problem populating a jsgrid from with JSON data and I have scaled down the code to a very minimal implementation but it is still not working. I can see in the Chrome debugger that the REST call returns data on this format

{data: [{ "Name":"MyAccount"}]}

Anyone who can see what is wrong?

<script>
   

    $(function () {

        $("#jsGrid").jsGrid({
            height: "auto",
            width: "100%",

            sorting: true,
            paging: false,
            autoload: true,
           
            controller: {
                loadData: function (filter) {
                    console.log(filter);
                    return $.ajax({
                        type: "GET",
                        url: "http://localhost:8888/GetListJSGrid",
                        data: filter,
                        dataType: "json"
                    });
                }
            },
           
            fields: [
             { name: "Name", type: "text", width: 150 }
            ]
        });
    });

4

2 回答 2

3

返回数据的格式应该是项数组,而不是带data字段的 JSON 对象。

请注意,对于按页面 ( pageLoading: true) 加载,此格式不同:{ data: [arrayOfItems], totalCount: amountOfItems }.

对于上面的代码,您可以执行以下操作:

loadData: function (filter) {
    console.log(filter);
    return $.ajax({
        type: "GET",
        url: "http://localhost:8888/GetListJSGrid",
        data: filter,
        dataType: "json"
    }).then(function(result) {
        return result.data;
    });
}
于 2017-03-18T22:33:33.200 回答
1

好的,我解决了。似乎没有为 JSGrid 更新文档,或者我在这里遗漏了一些东西。

通过比较下面在 JSGrid 中工作的链接的响应

ODataTest

我注意到 JSGrid {"value": [{ "Name":"MyAccount"}]} 接受了以下 JSON

于 2017-03-15T21:26:34.263 回答