如何通过cq.ext.button处理程序将变量传递给javascript函数? [英] How to pass variable to javascript function through cq.ext.button handler?
问题描述
dialog.xml中有以下代码
< toolbar
jcr:primaryType =cq:Widget
xtype =toolbar>
< items
jcr:primaryType =cq:WidgetCollection>
< input
jcr:primaryType =cq:Widget
xtype =textfield
name =./ myInput>
< / input>
< button
jcr:primaryType =cq:Widget
xtype =button
name =./ myButton
text =提交处理程序=function(){passMyInput()};>
< / button>
< / items>
我已经实现了 passMyInput()
如下:
passMyInput(){alert(test );}
这工作正常。我的问题是如何将 ./ myInput
的值传递给函数passMyInput
?
我尝试过 handler =function()passMyInput('./ myInput')};
但不起作用>
按钮的处理函数接收2个参数,按钮 b
和eventObject 电子
。
我们可以通过按钮获取容器对话框,然后使用 getField()
方法获取该字段
修改后的处理函数将是
function b,e){
var dlg = b.findParentByType('dialog');
var val = dlg.getField('./ myInput')。getValue();
passMyInput(val);
}
有关更多信息,请参阅小部件文档
I have the following code in my CQ dialog.xml
<toolbar
jcr:primaryType="cq:Widget"
xtype="toolbar">
<items
jcr:primaryType="cq:WidgetCollection">
<input
jcr:primaryType="cq:Widget"
xtype="textfield"
name="./myInput">
</input>
<button
jcr:primaryType="cq:Widget"
xtype="button"
name="./myButton"
text="Submit" handler ="function() {passMyInput()};">
</button>
</items>
I have implemented the function passMyInput()
as follow:
passMyInput(){ alert("test");}
This works fine. My question is how to pass the value of ./myInput
to the function passMyInput
?
I have tried handler ="function() passMyInput('./myInput')};"
but it doesn't work
The button's handler function receves 2 arguments, button b
and eventObject e
.
We can obtain the container dialog through the button and then use the getField()
method to obtain the value of the field.
The modified hander function would be
function(b, e) {
var dlg = b.findParentByType('dialog');
var val = dlg.getField('./myInput').getValue();
passMyInput(val);
}
For more info, refer widget docs
这篇关于如何通过cq.ext.button处理程序将变量传递给javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!