2016-12-29 4 views
0

すべてのjsファイルとcssファイルを含むhtmlページにデータテーブルを追加しました。 私が望むのは、Webサービスからデータを取得するためにajax呼び出しを持つ別のjavascriptファイル関数からそのデータテーブルを初期化し、そのデータをデータテーブルに割り当てることです。他のjavascriptファイル関数からhtmlページにあるデータテーブルを初期化する

report.js

 function getReport(projectname){ // added for data table plugin 

     $.ajax({ 
      type:"GET", 
      url:webCallUrl, 
      complete:function(data){   
      },error:function(){ 

      } 

     }) 

    } 

test1.html

 <div id="graphic12"> 
     <table id="example" class="display" width="100%"></table> 
$(document).ready(function() { 

     $('#graphic').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>'); 

     console.log(dataArr); 

     var table=$('#example').DataTable({ 
      "aaData": dataArr, 
      "aoColumns": [ 
       {"title": "organization"}, 
       {"title": "project"}, 
       {"title": "open_tickets"} 
       ] 
}); 
}); 

答えて

0

thisを試してみてください。私の知る限り、このプラグインにはオプションが組み込まれています。それ以外の場合は約束を使用してください:

function getReport(projectname) { 
    return $.ajax({ 
    type: "GET", 
    url: webCallUrl, 
    complete: function (data) { 

    }, 
    error: function() { 

    } 
    }) 
} 

getReport().then(function (dataArr) { 
    $('#example').DataTable({ 
    "aaData": dataArr, 
    "aoColumns": [ 
     {"title": "organization"}, 
     {"title": "project"}, 
     {"title": "open_tickets"} 
    ] 
    }); 
}) 
関連する問題