Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery插件和JS脚本之间的Grails冲突_Javascript_Jquery_Grails - Fatal编程技术网

Javascript jQuery插件和JS脚本之间的Grails冲突

Javascript jQuery插件和JS脚本之间的Grails冲突,javascript,jquery,grails,Javascript,Jquery,Grails,我有一个Grails应用程序需要jQuery,所以我通过插件加载jQuery和jQuery UI: buildConfig.groovy: runtime ":jquery:1.11.1" compile ":jquery-ui:1.10.4" 只要我不包含也使用jQuery的独立JS脚本,这就可以了。这个脚本名为myscript.jquery.js,我把它放在web app/js下 现在我在main.gsp中包含了这些插件和脚本: main.gsp: <html>

我有一个Grails应用程序需要jQuery,所以我通过插件加载jQuery和jQuery UI:

buildConfig.groovy:
    runtime ":jquery:1.11.1"
    compile ":jquery-ui:1.10.4"
只要我不包含也使用jQuery的独立JS脚本,这就可以了。这个脚本名为myscript.jquery.js,我把它放在web app/js下

现在我在main.gsp中包含了这些插件和脚本:

main.gsp:
<html>
<head>
      ...

<r:require modules='jquery, jquery-ui, bootstrap, customcss' />
<g:javascript src="myscript.jquery.js"/>

<r:layoutResources disposition="defer" />

<g:layoutHead/>
<r:layoutResources disposition="head"/>

</head>
<body>
      ...
我犯了一个特别的错误吗? 有没有更好的方法来处理这个问题


PS:我试图通过main.gsp中的脚本直接加载jQuery,但没有成功,因为我还有其他依赖于jQuery插件的插件:-/

在config中的ApplicationResources.groovy文件中添加脚本,然后在页面中添加该模块。这将解决问题

例如: 在conf/ApplicationResources.groovy中

modules = {
    baseJS {
        resource url: 'js/myscript.jquery.js'
    }
}
在你的gsp文件中

<r:require modules='jquery, jquery-ui, bootstrap, customcss, baseJS' />

这是一个老博客,但你会明白的


谢谢

看看生成的html,看看jquery是出现在自定义js之前还是之后。我认为r:require后面跟着g:javascript可能是原因,请尝试从r:require中删除jquery,并在自定义调用上方将其定义为g:javascript
<r:require modules='jquery, jquery-ui, bootstrap, customcss, baseJS' />