2013-04-29 10 views
0

我正在調用Datatables mRender函數內的ajax函數,該函數將使用當前ajax源的id從不同的ajax源獲取數據。調用Ajax在mRender中獲取函數Datatable

要地理解這一點,我有:

從不同客戶在一個數據表申請的列表。

在此列表中我有一個客戶端ID。我想讓客戶名稱顯示在表格上而不是客戶端ID上。但客戶名稱和其他客戶端詳細信息位於客戶表中,因此這些詳細信息不在請購單json數據中。但我有客戶端ID。

如何使用它獲取mrender函數中的客戶名稱?例如

{"sTitle":"Client","mData":null, 
    "mRender":function(data){ 
    //ajax function  
    } 
}, 

在此先感謝您, 此致敬禮。

+0

我也在尋找這樣做,你有解決這個問題嗎? – 2017-06-14 06:43:50

回答

0

我不相信這是你應該如何處理你的數據。不過,我也在我的mRender函數中使用了一個AJAX數據源,如下所述。

$(document).ready(function(e){ 
     $('.products').dataTable({ 
      "bProcessing": true, 
      "sAjaxSource": window.location.protocol + "//" + window.location.hostname + '/product/getAll', 
      "aoColumns": [ 
       { "sTitle": "Pid", "bVisible" : false}, 
       { "sTitle": "Pname" }, 
       { "sTitle": "Pprice" }, 
       { "sTitle": "Pgroups", 
        "mRender" : function(data, type, full){ 
         console.log(data, type, full); 
         console.log(category.getAll()); 
         return 'test'; 
        } 
       } 
      ] 
     }); 
    }); 

德類別物體在selfinvoking功能初始化。我用它來防止函數在每次調用函數時遠程加載數據。 它看起來像這樣:

(function(){ 
     if(typeof category === 'undefined'){ 
      category = {}; 
     } 
     category.getAll = function(){ 
      if(typeof category.all === 'undefined'){ 
       $.ajax({ 
        'type' : 'POST', 
        'async': false, 
        'url' : window.location.protocol + "//" + window.location.hostname + "/category/getAll", 
        'success' : function(data){ 
         console.log(data); 
         category.all = data; 
        }, 
        'error': function(a,b,c){ 
         console.log("You shall not pass!",a,b,c); 
         alert('stop'); 
        } 
       }); 
      } 
      return category.all; 
     } 
    })();