我正在尝试使用我的 portlet javascript 代码调用 json 网络服务:
在 js/main.js
我有:
Liferay.Service(
'/Basic-portlet.hello/remote-hello',
{
name: ''
},
function(obj) {
console.log(obj);
}
);
此调用仅在我将 portlet 添加到页面时执行一次,每当页面重新加载时引发 javascript 错误:
Uncaught TypeError: undefined is not a function
A.mix.parseIOConfig
A.mix.parseInvokeArgs
Service main.js?browserId=other&lan....
(anonymous function)
最佳答案
当您尝试从没有访问 AlloyUI 的上下文中调用 Liferay JSON Web 服务时,我已经看到了这种情况。
添加以下 AUI 导入:
<script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script>
然后像这样包装您的服务调用:
AUI().use('aui-base', function(A){
// Liferay Service invocation here
});
例如,
AUI().use('aui-base', function(A){
Liferay.Service(
'/user/get-user-by-email-address',
{
companyId: Liferay.ThemeDisplay.getCompanyId(),
emailAddress: 'test@liferay.com'
},
function(obj) {
console.log(obj);
}
);
});
关于javascript - Liferay:从 portlet 调用 JSON 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29512686/