Jquery datatable in play framework - $(“#example”)。dataTable不是一个函数 [英] Jquery datatable in play framework - $("#example").dataTable not a function

查看:193
本文介绍了Jquery datatable in play framework - $(“#example”)。dataTable不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码

 #{extends'main.html'/} 
#{set title:'Customers List'/}
< link rel =stylesheetmedia =screen href =@ {'/ public / stylesheets / demo_table.css'}>
< link rel =stylesheetmedia =screenhref =@ {'/ public / stylesheets / demo_page.css'}>
#{set'moreScripts'}
< script src =@ {'/ public / javascripts / jquery-1.5.2.min.js'}type =text / javascriptcharset = $ {_ response_encoding}>< / script>
< script src =@ {'/ public / javascripts / jquery.dataTables.js'}type =text / javascriptcharset =$ {_ response_encoding}>< / script>
< script src =@ {'/ public / javascripts / jquery.js'}type =text / javascriptcharset =$ {_ response_encoding}>< / script>
< script>
$(document).ready(function(){
oTable = $('#example')。dataTable();
});
< / script>
#{/ set}
< div class =othersalign =center>
< table width =100%cellpadding =0cellspacing =0border =0class =displayid =example>
< thead>
< tr>
< th> Header1< / th>
< th> Header2< / th>
< / tr>
< / thead>
< tbody>
< tr>
< td> Col1< / td>
< td> Col2< / td>
< / tr>
< / tbody>
< / table>
< / div>

当我运行该页面时,JavaScript会抛出错误

  $(#example)。dataTable不是一个函数


$ b $我检查了所有的javascript / css文件。所有文件都包含在内。
什么可能是错误。

解决方案

你必须在你的jQuery中加载数据表脚本部分,您必须只包含一次jQuery。



尝试删除第二个(非最小化的)jQuery请求,看看你如何去。


I'm trying to implement JQuery datatables in my play application.

Here is my code

    #{extends 'main.html' /}
    #{set title:'Customers List' /}
    <link rel="stylesheet" media="screen" href="@{'/public/stylesheets/demo_table.css'}">
    <link rel="stylesheet" media="screen" href="@{'/public/stylesheets/demo_page.css'}">
    #{set 'moreScripts'}
    <script src="@{'/public/javascripts/jquery-1.5.2.min.js'}" type="text/javascript" charset="${_response_encoding}"></script>
    <script src="@{'/public/javascripts/jquery.dataTables.js'}" type="text/javascript" charset="${_response_encoding}"></script>
    <script src="@{'/public/javascripts/jquery.js'}" type="text/javascript" charset="${_response_encoding}"></script>
    <script>
        $(document).ready( function() {
            oTable = $('#example').dataTable();
        });
    </script>
    #{/set}
    <div class="others" align="center">
                    <table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="example">
                        <thead>
                        <tr>
                                <th>Header1</th>
                                <th>Header2</th>
                        </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>Col1</td>
                                <td>Col2</td>
                            </tr>
                        </tbody>
                    </table>
    </div>

When i run the page javascript throws an error

$("#example").dataTable is not a function

I checked all javascript/css files. All files were included. What could be the error.

解决方案

You must load DataTables AFTER jQuery in your scripts section, and you must only include jQuery once.

Try removing the second (non-minified) request for jQuery and see how you go.

这篇关于Jquery datatable in play framework - $(“#example”)。dataTable不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆