如何在liferay中获取客户端portlet id?
我正在liferay portlet中使用AlloyUI 我想在javascript中使用我的如何在liferay中获取客户端portlet id?,liferay,liferay-6,alloy-ui,Liferay,Liferay 6,Alloy Ui,我正在liferay portlet中使用AlloyUI 我想在javascript中使用我的的id。问题是元素的id在客户端发生了更改 例如: 如果我将的Id设置为“username”,则会将其更改为\u hospital\u WAR\u hospitalportlet\u username,即\u hospital\u WAR\u hospitalportlet\u将附加到Id之后,其中hospital是我的portlet名称 如何获取客户端Id以便在jquery中使用它?在的Id前面的字符
的id。问题是元素的id在客户端发生了更改
例如:如果我将
的Id设置为“username”,则会将其更改为\u hospital\u WAR\u hospitalportlet\u username
,即\u hospital\u WAR\u hospitalportlet\u将附加到Id之后,其中hospital
是我的portlet名称
如何获取客户端Id以便在jquery中使用它?在
的Id
前面的字符串\u hospital portlet\u
就是portlet名称空间
如果您使用
标记,则仅在
的名称
和id
属性前面加上此项,如果您仅使用普通html
标记,则不会更改名称
和id
属性
但是,使用
是一种很好的做法,因此可以执行以下操作以在javascript代码中获取portlet名称空间:
如果您在JSP中使用Java脚本,即在中使用代码>或
然后可以使用
或
在javascript中获取字符串\u hospital\u WAR\u hospitalportlet\u
,类似于
jQuery("#<portlet:namespace />username").val();
// Or
jQuery("#<%= renderResponse.getNamespace() %>username").val();
从JSP调用此函数:
<input type="button" onClick="changeValues('<portlet:namespace />')" />
希望这有帮助。我不知道是否有办法通过Liferay定义的javascript函数直接获取名称空间
或portletId
。如果你得到类似的东西,你可以把它贴在这里,这将非常有帮助。试试这个:
Liferay.Portlet.ready(
/*
This function gets loaded after each and every portlet on the page.
portletId: the current portlet's id
node: the Alloy Node object of the current portlet
*/
function(portletId, node) {
}
);
Liferay.Portlet.ready(
/*
This function gets loaded after each and every portlet on the page.
portletId: the current portlet's id
node: the Alloy Node object of the current portlet
*/
function(portletId, node) {
}
);