0

我希望在 Datatables mRender 函数中调用一个 ajax 函数,该函数将使用来自当前 ajax 源的 id 从不同的 ajax 源获取数据。

从这个角度来看,我有:

一个数据表中来自不同客户的申请列表。

在这个清单中,我有一个客户 ID。我想让客户端名称而不是客户端 ID 显示在表格上。但是,客户名称和其他客户详细信息在客户表中,因此这些详细信息不在申请 json 数据中。但我有客户 ID。

如何使用它在 mrender 函数中获取客户端名称?例如

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

预先感谢您,问候。

4

1 回答 1

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';
                   }
               }
            ]
        });
    });

类别对象在自调用函数中初始化。我用它来防止函数在每次调用函数时远程加载数据。它看起来像这样:

    (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;
        }
    })();
于 2014-03-26T09:39:48.360 回答