Reputation: 73
In objective c we can pass data between two classes very easily by nextClassname.recievedVariable = passedVariable;
i tried same with titanium, but failed
I tried as follows
in Second Class
$.table.addEventListener('click', function(e) {
var selected = e.row;
alert(e.row.title);
var TodayStatus = Titanium.UI.createWindow({ url:'TodayStatus.js' });
TodayStatus.seletedProj = e.row.title;
// var TodayStatus = new Alloy.createController("TodayStatus");
TodayStatus.getView().open();
});
in the first Calss whic we have to recieve string from another class
var win = Ti.UI.currentWindow;
Ti.API.info(win.seletedProj);
But causes errors like
message = "'undefined' is not an object (evaluating 'win.seletedProj')";
[ERROR] : name = TypeError;
Upvotes: 0
Views: 955
Reputation: 1652
You can pass the data by passing parameter like this.
x.addEVentListener('click', function(e){
var controller = require('controllerPath').createWindow(e.value);
controller.open();
})
And in controller.js
exports.createWindow = function(value)
{
//whatever You like to do with UI
}
Upvotes: 1
Reputation: 33345
see link here for how to do it in Alloy,
https://github.com/aaronksaunders/alloy_fugitive/blob/master/app/controllers/Fugitives.js#L29
but basic idea is to pass the object as a parameter when creating the new controller.
$.table.addEventListener('click', function(_e) {
var detailController = Alloy.createController('FugitiveDetail', {
parentTab : $.fugitiveTab,
data : fugitiveCollection.get(_e.rowData.model)
});
$.fugitiveTab.open(detailController.getView());
});
The link I provided has a complete solution using Alloy
Upvotes: 0
Reputation: 627
If you create a new window by using the 'url' parameter it automatically puts that code into it's own Sub-context and it isn't possible to pass complex objects accross, see here:
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.Window
I don't tend to do it this way anymore.
The way i would do it would be to create your todayStatus window as a common js class:
// todayStatus.js
var win = Ti.UI.createWindow({ top:0, left: 0, right: 0, bottom:0, etc... });
//any extra visual building code can go here
win.open();
exports.seletedProj = function(rowTtl){
//this function is available outside the class
}
Then you can reference it from your main class like this:
// main.js
var TodayStatus = require('todayStatus');
TodayStatus.seletedProj(e.row.title);
etc...
Hope that helps
Upvotes: 0