如何在钛合金中以编程方式添加控件

时间:2014-08-23 11:19:56

标签: titanium titanium-mobile titanium-alloy

我正在尝试以编程方式在钛合金中添加控件。 我做了快速的代码,但它不工作,我不知道为什么??

XML

<Alloy>
  <Window class="container">
        <View id="TextOrders">
        <ScrollView id="scrollView" showVerticalScrollIndicator="true" showHorizontalScrollIndicator="true" >

        </ScrollView>
      </View>
    </Window>
</Alloy> 

控制器

var args = arguments[0] || {};
var TextOrders = Ti.UI.createView({
  backgroundColor:'white'
});
function createRow(i) {
  var row = Ti.UI.createView({
    backgroundColor: 'white',
    borderColor: '#bbb',
    borderWidth: 1,
    width:'100%', height: 70,
    top: 0, left: 0
  });
  var inputTextField = Ti.UI.createTextField({
    hintText: 'Enter value ' + i,
    keyboardType: Ti.UI.KEYBOARD_NUMBERS_PUNCTUATION,
    top: 10, left: '10%',
    width: '80%', height: 60
  });
  row.add(inputTextField);
  return row;
}
var scrollView = Ti.UI.createScrollView({
  bottom:120,
  contentHeight: 'auto',
  layout: 'vertical',
   backgroundColor: 'red',
   height:'58%'
});

for(var i = 0; i <= 20; i++){
    var row = createRow(i);
    scrollView.add(row);
}
TextOrders.add(scrollView);

tss

".container" : {
  backgroundColor:"white"
}
"#TextOrders":{
    width:'100%',
    height:'57%',
    borderColor:'red',
    borderWidth:'1px',
    top:'0px',
}
"#scrollView":{
    width:'80%',
    borderColor:'blue',
    borderWidth:'1px',
    top:'0px',
    height:'80%',
}

它没有给我任何错误,但没有添加控件。

1 个答案:

答案 0 :(得分:0)

TextOrders.add(scrollView);

应该是:

$.TextOrders.add(scrollView);

相关问题