javascript - 在nativescript中使用tap函数传递参数

标签 javascript parameter-passing nativescript

我想做这样的事情,但它不以这种方式工作。 这是 xml 代码:

<image id="CustomerRadioButton" src="{{ CustomerRBSrc }}" class="RadioButton" tap="CustomerTypeRadioButtonOnTap('C')"/>

如何在js代码中获取这个参数?

最佳答案

您可以通过多种方法在 PAN(Plain Awesome Nativescript)应用程序中处理此问题。

  1. 您可以调用自定义函数,然后调用正确的函数,即按钮设置为: CustomerTypeRadioButtonOnTapC = () { CustomerTypeRadioButtonOnTap('C'); }

  2. 您可以在图像上设置自定义属性 - 即 <image id="CustomerRadioButton" src="{{ CustomerRBSrc }}" class="RadioButton" tap="CustomerTypeRadioButtonOnTap" customerType="C"/>

然后

 function CustomerTypeRadioButtonOnTab (args) {
     console.log(args.object.customerType);  // Should be "C" 
 }

关于javascript - 在nativescript中使用tap函数传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52135591/

相关文章:

javascript - 获取 HTML 元素的所有数据属性顺序

javascript - 带有文本形式替代的 Bootstrap 子菜单?

c - 指向指针数组的指针返回初始地址

typescript - 如何使用 @viewChild 在我的组件中获取 bradmartin/nativescript-videoplayer 元素引用?

NativeScript:运行 TNS Doctor 时仍然收到 "Android SDK Is Not Installed Error"

NativeScript - 从 Nativescript 应用程序启动另一个应用程序

javascript - 音轨 JS 函数不播放或暂停音频

javascript - 这种类型的 webservice 是如何使用 JSON 抛出幻灯片图像的?

c++ - 什么时候删除由 (char *) 作为函数参数指向的内存?

google-maps-api-3 - Javascript 将参数传递给回调或在 DistanceMatrixStatus 中设置变量值