DataTables and requireJs work well
DataTables and requireJs work well
 nel            
            
                Posts: 1Questions: 0Answers: 0
nel            
            
                Posts: 1Questions: 0Answers: 0            
            when i use datatables with requireJs, i got a error as '$(...).DataTable is not a function'.
i open the source file and find something is worry in AMD way, and then it works well. just look here:
(/** lends <global> */function( window, document, undefined ) {
(function( factory ) { ......}
(/** lends <global> */function( $ ) { //notice1, here define $ as a param of this func, the $ is not the global $, but where it was send!!!
      ......
      return $.fn.dataTable;   // notice 2, this func will return something, but if it does't be called, nothing will happen!!!
}));   
}(window, document));
so i change the source as :
(/** lends <global> */function( window, document, undefined ) {
(function( factory ) { ......}
(/** lends <global> */function(  ) { //notice1, remve $ and use a global $.
      ......
      return $.fn.dataTable;   // notice 2, add () to call this func. see noticec 3.
}()));   //notice 3.add () here.
}(window, document));
of couse, it works weel.
you also can use like this:
(/** lends <global> */function( window, document, undefined ) {
(function( factory ) { ......}
(/** lends <global> */function( $ ) { //notice1, keep $ and use a  param $.
      ......
      return $.fn.dataTable;   // notice 2, add () to call this func. see noticec 3.
}($)));   //notice 3.add () here. and send $ as a param.
}(window, document));
in a word, the func '(/** @lends <global> */function( $ )' will change something for working well in AMD, because the $ param is defined and the func should run autoly . good luck!
This discussion has been closed.
            
Replies
Thanks for your feedback - I'll look into this in more depth.
Allan