如何在新窗口中显示更新的值

时间:2013-12-12 12:41:56

标签: titanium appcelerator nan

我想问一下,当我将数据输入textarea时,我无法在新窗口中得到结果。 我的意思是,当我单击计算按钮时,结果显示NaN。我无法处理如何做到这一点。代码如下

有人可以通知我吗?

Titanium.UI.setBackgroundColor('white');


var win1 = Ti.UI.createWindow({

    title : 'Welcome to BMI'
});

var win2 = Ti.UI.createWindow({
        title:'BMI'
});

var win3 = Ti.UI.createWindow({
        title:'BMI'
});


var win4 = Ti.UI.createWindow({
    title:'BMI'


});
win4.addEventListener('open', function(e){

    textAreaHeight.value/textAreaWeight.value;



});

var label1 = Ti.UI.createLabel({
    top: 100,
    text:'Welcome to BMI',
    color : 'blue',
    font: { fontSize:48 }

});






var standardButton = Ti.UI.createButton(
    {
    title:'Standart',
    top : 250,
    height:50,
    width: 200
});
    standardButton.addEventListener('click', function(e)
    {
        win1.close();
        win2.open();
});



var metricButton = Ti.UI.createButton(
    {
    title:'Metric',
    top : 350,
    height: 50,
    width: 200
});
    metricButton.addEventListener('click', function(e)
    {
        win1.close();
        win2.open();    
});


var labelHeight = Ti.UI.createLabel({
        text:'Height',
    color:'red',
    top:300,
    left:100,
    font: { fontSize:24 },
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
    width: Ti.UI.SIZE, height: Ti.UI.SIZE
});

var HeightValue = Titanium.App.Properties.getInt("HeightValue");
var textAreaHeight = Ti.UI.createTextArea({
  value : HeightValue,
  borderWidth: 2,
  borderColor: '#bbb',
  borderRadius: 5,
  color: '#888',
  font: {fontSize:20, 
  fontWeight:'bold'},

  left:200,
  top: 300,
  width: 125, 
  height : 40

  });

    textAreaHeight.addEventListener('click', function(e) {
    textAreaHeight.blur();
    Titanium.App.Properties.setInt("HeightValue", e.value);

    });

var labelWeight = Ti.UI.createLabel({
    text : "Weight",
    color:'red',
    top:400,
    left:100,
    font: { fontSize:24 },
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
    width: Ti.UI.SIZE, height: Ti.UI.SIZE
});


var WeightValue = Titanium.App.Properties.getInt("WeightValue");
var textAreaWeight = Ti.UI.createTextArea({
  value : WeightValue,
  borderWidth: 2,
  borderColor: '#bbb',
  borderRadius: 5,
  color: '#888',
  font: {fontSize:20, 
  fontWeight:'bold'},

  left:200,
  top: 400,
  width: 125, 
  height : 40
 });

    textAreaWeight.addEventListener('click', function(e) {
    textAreaWeight.blur();
    Titanium.App.Properties.setInt("WeightValue", e.value);

    });

var CalculatorButton = Ti.UI.createButton({
    title:'Calculate',
    top:475,
    width:400,
    height:90,
    left:75
});

     CalculatorButton.addEventListener('click', function(e){
     //alert(textAreaHeight.value);
     //alert(textAreaWeight.value);

     win2.close();
     win4.open();
});



     var BMILabel = Ti.UI.createLabel({
            text:textAreaHeight.value/textAreaWeight.value,
            font:{fontSize:84},
            color:'red',
            textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
            top:100

        });

var ExitButton = Ti.UI.createButton({
    title:'Exit',
    top:475,
    width:400,
    height:90,
    left:500
});
    ExitButton.addEventListener('click', function(e)
    {
        win2.close();
        win1.open();
    });


win2.add(ExitButton);
win2.add(CalculatorButton);
//win2.add(BMILabel);
win2.add(labelHeight);
win2.add(textAreaHeight);
win2.add(labelWeight);
win2.add(textAreaWeight);
//win4.add(textAreabmi);
win4.add(BMILabel);


win1.add(standardButton);
win1.add(metricButton);
win1.add(label1);
win1.open();

1 个答案:

答案 0 :(得分:0)

试试这个

CalculatorButton.addEventListener('click', function(e){
     win4._myValue = textAreaWeight.value;
     win4.open();
     win2.close();
});


win4.addEventListener('open', function(e){

    alert(win4._myValue);

});

希望它对你有所帮助。