0
votes

how can i pass multiple values with a single button i a titanium alloy view to a function?

my button looks like this in view.xml:

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

controller.js

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

now the the console shows the correct values "val1" and "val2" (see [INFO]), but there is also a red error screen complaining about an invalid type passed to function:

[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

1 Answers

0
votes

I dont think you can pass value like you are trying. I think following solution will work properly :

View :

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

Controller :

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