I am using Titanium Alloy MVC with a project that needs to scan QR code Titanium SDK 3.4.0.GA
I have 2 controllers: index.js and secondwindow.js with their respective views index.xml and secondwindow.xml. I need to start the scan and handle the result of the scan in secondWindow controller, and return that result to the index controller, to let index handle his UI elements
Im trying something like this index.xml:
<Alloy>
<Window>
<Label id='result' />
...Other components...
<Button onClick='startScan'>Start QR scan</Button>
</Window>
</Alloy>
index.js:
function whenSecondWindowFinish(arg){
//update index.xml
$.result.setText(arg);
}
function startScan(e){
Alloy.createController('secondWindow');
}
$.index.open();
secondWindow.xml:
<Alloy>
<Window exitOnClose='false'>
</Window>
</Alloy>
secondWindow.js:
function scanOK(data){
var returnResult = /*Handle data*/
//I need to return the result to the index controller
$.secondWindow.close();//And close this view
}
function canceled(){
//return {} to index controller
$.secondWindow.close();//And close this view
}
var QRscanner = require('qrscanner');
var qroptions = {
//width height ...
success: scanOK,
cancel: canceled
};
var qrview = QRscanner.createQRView(qroptions);
$.secondWindow.add(qrview);
$.secondWindow.open();
How can I close this window in the success/cancel functions and return the result to the index controller or notify index to execute whenSecondWindowFinish(/pass arg of scan result/); method? Or which is the correct way to do that?
secondWindow.jstoindex.js( am i correct ?) and what is the type of result you want to send ( String , object , other ) ? - turtle