钛合金通过按钮传递多个值

时间:2014-12-20 14:03:05

标签: button titanium titanium-alloy multiple-value

如何通过单个按钮传递多个值?钛合金视图到函数?

我的按钮在view.xml中显示如下:

<Button id="star4" onClick="vote1('value1', 'value2')" />

controller.js

function vote1 (val1, val2) {
console.log(val1 + val2 + "this is val1 and val2");

现在控制台显示正确的值“val1”和“val2”(参见[INFO]),但是还有一个红色错误屏幕,抱怨传递给函数的类型无效:

[ERROR] :  Script Error {
[ERROR] :      backtrace = "#0 () at     
...
[ERROR] :      line = 395;
[ERROR] :      message = "Invalid type passed to function";
**[INFO] :   value1value2this is val1 and val2**
[ERROR] :      nativeLocation = "-[TiProxy addEventListener:] (TiProxy.m:824)";
[ERROR] :      nativeReason = "expected: Function, was: NSNull";
...
[ERROR] :  }

}

1 个答案:

答案 0 :(得分:0)

我认为你不能像你正在尝试那样传递价值。我认为以下解决方案将正常运作:

查看:

<Button id="star4" value1="xyz" value2="mno" onClick="vote1" />

控制器:

function vote1(e) {
   var value1 = e.source.value1;
   var value2 = e.source.value2;
}