2017-03-08 36 views
0

我想补充jQuery UI's datepicker我的Liferay 7门户,但我不断收到此错误:如何将jQuery UI的datepicker添加到Liferay 7 portlet?

Object doesn't support property or method '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库,所以我不需要在本地下载并引用它。

有没有什么办法可以使用这个datepicker,或者我应该使用AlloyUI的吗?

回答

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的应用程序中添加库,你会得到一个错误 - 不匹配匿名定义()模块:

为了克服这个问题,您需要更改库就像

(function(factory) { factory(jQuery); }(function($) {

你正在做的是删除引起问题的定义调用的引用,因为默认情况下已经加载了jQuery。 您需要为其他包含调用的JS库执行相同的事情。

+0

我到底需要改变这一点?我需要“修补”jQuery.js文件吗? –

+0

@a_horse_with_no_name不,任何jQuery依赖库.. 即slick.js,jquery ui等等。简而言之,任何依赖于jQuery的js –