我试图存储对数组中的几个文本字段的引用。当我尝试访问数组的元素时,我得到了一些整数而不是textfield对象!我想不通为什么会这样......钛textField存储为整数
输出后var textfields = [];
function doClick(e) {
var txtField = Ti.UI.createTextField({
value:"test"
});
textfields.push(txtField);
$.index.add(txtField);
for(var textfield in textfields) {
console.log("stored value : "+textfield);
}
}
$.index.open();
三“点击”:
[INFO] : ---click---
[INFO] : stored value : 0
[INFO] : ---click---
[INFO] : stored value : 0
[INFO] : stored value : 1
[INFO] : ---click---
[INFO] : stored value : 0
[INFO] : stored value : 1
[INFO] : stored value : 2
然而,当我字符串化整个数组,我看到文本框里面,但我不”不知道如何访问它。 这里有两个文本框里面的数组:
[
{
"enabled":true,
"selection":{
"length":0,
"location":0
},
"backgroundRepeat":false,
"children":[
],
"rect":{
"height":45,
"y":61,
"x":137,
"width":47
},
"value":"voilà",
"visible":true,
"size":{
"height":45,
"y":0,
"width":47,
"x":0
},
"keepScreenOn":false,
"apiName":"Ti.UI.TextField",
"maxLength":-1,
"bubbleParent":true
},
{
"enabled":true,
"selection":{
"length":0,
"location":0
},
"backgroundRepeat":false,
"children":[
],
"rect":{
"height":45,
"y":107,
"x":137,
"width":47
},
"value":"voilà",
"visible":true,
"size":{
"height":45,
"y":0,
"width":47,
"x":0
},
"keepScreenOn":false,
"apiName":"Ti.UI.TextField",
"maxLength":-1,
"bubbleParent":true
}
]
据我了解,textfield.value应该工作,但因为文本框本身是一个数字,它返回“未定义” ...我如何访问我存储在元素数组?
尝试调用文本框[“值”] –
这也是不确定的,但感谢您的尝试。 – midemarc
你不应该将textfields串起来!只需循环遍历它们,并获取值 –