Commonjs-在Appcelerator中使用Titanium将数据从一个窗口移动到另一个窗口

时间:2018-09-04 17:58:00

标签: javascript titanium appcelerator appcelerator-titanium commonjs

当我使用require()在页面上按下按钮时,我试图从主窗口传递数据,就像这样:

mapview.addEventListener('click', function(evt) {
    var detailWindow = Ti.UI.createWindow({
            backgroundColor: '#333333',
            navTintColor: '#FFF',
            barColor: '#222222',
            itemID: evt.annotation.myid
        });
        Ti.API.info('detailWindow.itemID = ' + detailWindow.itemID); 
        // displays expected value from database eg 12345

        detailWindow = require('ui/iphone/detail');
        var detailWin = new myWindowHere(detailWindow.itemID);
}

Detail.js:

function myWindowHere(myItemID) {
    var myDetailsWin = Titanium.UI.createWindow({
    //properties here
    });
    Ti.API.info('myItemID = ' + myItemID); // this log is never 
    var facilityID = myItemID;

    myWindowHere.open();

    return myDetailsWin;
};
module.exports = myWindowHere;  

但是,当我收到错误消息:Can't find variable: myItemID

时,我在某个地方出错了

请帮助!非常感谢

1 个答案:

答案 0 :(得分:0)

尝试:

mapview.addEventListener('click', function(evt) {
    var detailWindow = Ti.UI.createWindow({
        backgroundColor: '#333333',
        navTintColor: '#FFF',
        barColor: '#222222',
        itemID: evt.annotation.myid
    });
    Ti.API.info('detailWindow.itemID = ' + detailWindow.itemID); 
    // displays expected value from database eg 12345

    var detailWin = require('ui/iphone/detail').myWindowHere(detailWindow.itemID);
}