使用SammyJS在DataTables的文档加载/就绪上加载JSON

时间:2014-03-20 15:27:09

标签: ajax json datatables jquery-datatables sammy.js

选择视图并刷新页面时,DataTable不会加载,但仅在从导航中触发视图后才会加载。如何在页面刷新时加载视图,而不仅仅是触发?

this.get('#/campaigns/orders', function (context) {
        this.partial('/Orders/');
        $.ajax({
            url: '/api/orders',
            dataType: 'json',
            success: function (data) {
                var orders = $('#results').dataTable({
                    "bProcessing": true,
                    "sAjaxSource": '/api/orders',
                    "aoColumns": [
                        { "mData": "Name" },
                        { "mData": "Budget" },
                        { "mData": "StartDate" },
                        { "mData": "EndDate" },
                        { "mData": "Status" },
                        { "mData": "Created" },
                        { "mData": "Changed"}
                    ]
                });
            }
        });
    });

1 个答案:

答案 0 :(得分:0)

this.get('#/campaigns/orders', function (context) {
    this.partial('/Orders/');
    $.ajax({
        url: '/api/orders',
        dataType: 'json',
        success: function (data) {
          $("document").on(load, function(){  
          var orders = $('#results').dataTable({
                "bProcessing": true,
                "sAjaxSource": '/api/orders',
                "aoColumns": [
                    { "mData": "Name" },
                    { "mData": "Budget" },
                    { "mData": "StartDate" },
                    { "mData": "EndDate" },
                    { "mData": "Status" },
                    { "mData": "Created" },
                    { "mData": "Changed"}
                ]
            });
          });
        }
    });
  });

这未经过测试......这只是为了得到一个想法,

如果它不起作用,请尝试替换

  $("document").on("load", function(){});

   $("document").ready(function(){     });