0

我有一个钛新手。我尝试创建新页面,但发现错误

[错误]:脚本错误 = 找不到变量:newCard.js 中的模块(第 21 行)。[错误]:脚本错误 = 'undefined' 不是 FirstView.js 中的对象(评估 'Ti.include("ui/common/newCard.js").createWindow')(第 46 行)。

这是我的测试代码

    function FirstView() {  
    var self = Ti.UI.createView();  

    var label = Ti.UI.createLabel({
        color:'black',
        text:String.format(L('welcome'),'(test)'),      
        top:'50',
        align:'center',
        height:'auto',
        width:'auto'
    });
    self.add(label);

    var txtClick=Ti.UI.createLabel({
        text:String.format(L('txtclick'),'- click here -'),
        color:'red',
        top:'180',
        align:'center',
        height:'auto',
        width:'auto'        
    });
    self.add(txtClick); 

    var show=Ti.UI.createImageView({
        top:'100',
        width:'172',
        height:'52',
        image:'/images/logo.png' 
    });
    self.add(show); 

    txtClick.addEventListener('click', function(e) {    
       var window = Ti.include("ui/common/newCard.js").createWindow({
        title:"new card a day"
       });
       window.open({
            animated:true
       }); 
    });

    return self;
}
module.exports = FirstView;

和 cardNew.js

        function newCard(){
        var self = Ti.UI.createView({
            backgroundColor: 'black',
        });

        var show=Ti.UI.createImageView({
            top:'100',
            width:'172',
            height:'52',
            image:'/images/logo.png' 
        });
        self.add(show);

        return self;
    }
module.exports = newCard;

请帮我。谢谢

4

1 回答 1

4

Try to change your code to this inside the eventlistener's callback:

var newCard = require("ui/common/newCard");
var win = new newCard();
win.open({animated:true});
于 2013-01-14T11:58:36.880 回答