我试图将jQuery UI's datepicker添加到我的Liferay 7 portlet中,但我一直收到此错误:
对象不支持属性或方法' datepicker'
我正在设置依赖关系:
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.tests",
"com.liferay.portlet.header-portlet-javascript=https://code.jquery.com/ui/1.12.1/jquery-ui.js",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=Advanced Date Picker",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
所以我在portlet上看到的只是没有任何脚本功能的输入字段。 我从第7版开始读到,Liferay已经预先实现了一个基本的jQuery库,所以我不需要在本地下载并引用它。
有没有办法使用这个提到的日期选择器,还是应该使用AlloyUI的?
答案 0 :(得分:2)
如果要将liferay 7主题/ portlet /应用程序与jQuery UI集成,则需要对jQuery UI库本身进行细微更改。
默认情况下,库以 -
开头 (function( factory ) { if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. define([ "jquery" ], factory ); } else { // Browser globals factory( jQuery ); } }(function( $ ) {
如果直接在liferay应用程序中添加库,则会出现错误 - 匿名的define()模块不匹配:
要解决此问题,您需要更改库
(function( factory ) { factory( jQuery ); }(function( $ ) {
你正在做的是删除定义调用的引用,这会引起问题,因为jQuery已经默认加载了。 您需要为包含该调用的其他JS库执行相同的操作。