如何通过cq.ext.button处理程序将变量传递给javascript函数? [英] How to pass variable to javascript function through cq.ext.button handler?

查看:125
本文介绍了如何通过cq.ext.button处理程序将变量传递给javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的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 =提交处理程序=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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆