2016-06-17 38 views
2

我在使用requirejs加載數據表時遇到了問題。

以下是我的代碼

require.config({ 
    paths: { 
     "datatables" : "https://cdn.datatables.net/u/dt/jq-2.2.3,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.12,b-1.2.1,b-colvis-1.2.1,b-flash-1.2.1,b-html5-1.2.1,b-print-1.2.1,fc-3.2.2,fh-3.1.2,r-2.1.0,sc-1.4.2,se-1.2.0/datatables.min", 
    } 
}); 


requirejs(["datatables"], function() { 
    $('#example').DataTable({ 
     dom: 'Bfrtip', 
     buttons: [ 
      'copy', 'csv', 'excel', 'pdf' 
     ] 
    }); 
}); 

我從下面的鏈接產生datatables.min.js: https://www.datatables.net/download/

已經包含了jQuery和其他擴展,但我得到這個錯誤:

$(...).DataTable is not a function

任何人都可以幫助我嗎?

+0

難道你用你的代碼準備功能裏面? –

回答

0

你應該使用jQuery準備功能,例如:

requirejs(["datatables"], function() { 
    $(function(){ // ready function 
    $('#example').DataTable({ 
     dom: 'Bfrtip', 
     buttons: [ 
      'copy', 'csv', 'excel', 'pdf' 
     ] 
    }); 
    }); 
}); 
相關問題