Dandelion Datatables can't load jquery-ui

不打扰是莪最后的温柔 提交于 2019-12-12 05:39:52

问题


Recently I installed Dandelion datatables 1.1.1 and can't figure out how to activate jquery-ui which comes with the core library. I need that to use datepicker.

In my project the following architecture is used:

src
web 
|__ resources
    |__ css
    |__ js
|__ WEB_INF
    |__ views
        |__ ... html views
    |__ spring-servlet.xml

I load dandelion resources in spring-servlet via:

<mvc:resources mapping="/dandelion/**" location="classpath:/META-INF/resources/dandelion/"/>

In js folder I have datepicker-init.js :

$(document).ready(
  function () {
    $( "#datepicker" ).datepicker({
      changeMonth: true,
      changeYear: true
    });
  }
);

Then I try to load this script in my header

<script th:src="@{/resources/js/datepicker-init.js}"></script>

and then use it on my html page:

<html xmlns:th="http://www.thymeleaf.org"
      xmlns:dt="http://www.thymeleaf.org/dandelion/datatables">
               ....
              <div id="filter_panel">
                    <form th:action="@{/requests}" th:object="${requestRegisterModel}"
                          method="post">
                        <input id="datepicker" type="text" />
                    </form>
              </div>

but get Uncaught ReferenceError: $ is not defined error in browser console. I know that this error occurs because jquery-ui is not defined, but I can't load scripts in my header:

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>

because in this case jquery script loaded twice. I found similar issue here, but I thought, that it is possible to load jquery-ui without asset bundles, but still can't figure out how to do that. Everything else works just fine.

Browser console


回答1:


Ok, finally I've got this working. JQuery comes along with Dandelion Datatables, so there is no need to import it twice. But jquery is loaded only after the table is loaded, so I need to include script with jquery-ui

<script type="text/javascript" src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>

after table, for example in the footer.



来源:https://stackoverflow.com/questions/34218315/dandelion-datatables-cant-load-jquery-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!