// For a classic Titanium project, save the file to '
//-------------------------------------------------------------
1> create common JS module uunder "Lib" --- foo.js
var data = {};
function setData (obj){
data = obj;
}
function getData () {
return data;
}
// The special variable 'exports' exposes the functions as public
exports.setData = setData;
exports.getData = getData;
//--------------------------CONTROLLER and VIEW for FIRST WINDOW---
app/views/index.xml:
<Alloy>
<Window backgroundColor="blue">
<Label onClick="openWindow">Open the Red Window!</Label>
</Window>
</Alloy>
app/controllers/index.xml:
var foo = require('foo'); // importing the module
foo.setData({foobar: 42}); //calling setter function and passing object
function openWindow () {
var win2 = Alloy.createController('win2').getView();
win2.open();
}
$.index.open();
//--------------------------CONTROLLER and VIEW for SECOND WINDOW---------
app/views/win2.xml:
<Alloy>
<Window backgroundColor="red">
<Label id="label">I am a red window.</Label>
</Window>
</Alloy>
app/controllers/win2.js:
var foo = require('foo');
$.label.text = foo.getData().foobar;
//-------------------------------------------------------------
1> create common JS module uunder "Lib" --- foo.js
var data = {};
function setData (obj){
data = obj;
}
function getData () {
return data;
}
// The special variable 'exports' exposes the functions as public
exports.setData = setData;
exports.getData = getData;
//--------------------------CONTROLLER and VIEW for FIRST WINDOW---
app/views/index.xml:
<Alloy>
<Window backgroundColor="blue">
<Label onClick="openWindow">Open the Red Window!</Label>
</Window>
</Alloy>
app/controllers/index.xml:
var foo = require('foo'); // importing the module
foo.setData({foobar: 42}); //calling setter function and passing object
function openWindow () {
var win2 = Alloy.createController('win2').getView();
win2.open();
}
$.index.open();
//--------------------------CONTROLLER and VIEW for SECOND WINDOW---------
app/views/win2.xml:
<Alloy>
<Window backgroundColor="red">
<Label id="label">I am a red window.</Label>
</Window>
</Alloy>
app/controllers/win2.js:
var foo = require('foo');
$.label.text = foo.getData().foobar;
No comments:
Post a Comment