将Ajax数据传递给DataTable

时间:2017-11-04 19:44:29

标签: jquery angularjs ajax datatables

我正在使用angularJS和DataTables。我想在调用完成后加载DataTable。我在DataTables页面上获得了一些示例代码,但是我不明白我应该如何使用来自调用的实际数据来提供DataTable。这是到目前为止的代码:

     ImageService.getImages().then(function (value) {

        $('#adminTable').DataTable({
            "ajax": "data/objects.txt",
            "columns": [
                { "data": "ImageName" },
                { "data": "ImageCategory" },
                { "data": "Image" }
            ]
        });
    };

返回的Json看起来像这样

  [
    {
        "_id": "59fe0d54986fb50500005a76",
        "ImageName": "test55",
        "ImageCategory": "test77",
        "Image": [
            "59fe0d52986fb50500005a75"
        ]
    },
    {
        "_id": "59fdaee7986fb50500005696",
        "ImageName": "ghjskfda",
        "ImageCategory": "Red",
        "Image": [
            "59fdaee5986fb50500005695"
        ]
    },
    {
        "_id": "59fcbea1986fb5050000504a",
        "ImageName": "test4",
        "ImageCategory": "Light",
        "Image": [
            "59fcbe9f986fb50500005049"
        ]


     }
    ]

感谢您的帮助!

0 个答案:

没有答案