使用 Titanium Appcelerator mobile 1.7.2 添加元素后的空数组 [英] Empty array after adding elements using Titanium Appcelerator mobile 1.7.2

查看:23
本文介绍了使用 Titanium Appcelerator mobile 1.7.2 添加元素后的空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Titanium Appcelerator 移动 API 1.7.2.

I'm using Titanium Appcelerator mobile API 1.7.2.

创建数组时,我得到了一些奇怪的结果.这是我的语法吗?

When creating an array, I'm getting some odd results. Is it my syntax?

container.textBoxArray = new Array();
container.textBoxArray[0] = createPasswordTextField(options, '0%');
container.textBoxArray[1] = createPasswordTextField(options, '25%');
Ti.API.log(container.textBoxArray == null);
Ti.API.log('len: ' + container.textBoxArray.length);

输出的结果分别为 0(为假)和 'len: 0'.有人知道为什么吗?

The results of the output are 0 (for false) and 'len: 0' respectively. Anyone know why?

亚当

createPasswordTextField 本质上是

createPasswordTextField is essentially

function createPasswordTextField(options, left){
    return Ti.UI.createTextField( options... )
}

推荐答案

我也遇到过这种情况.将数组添加到 TiProxy 对象(视图、窗口、按钮等)时,它无法按预期工作.您需要操作阵列关闭"代理,然后重新设置它.我不知道这是一个错误还是只是 TiProxy 对象属性的限制.下面是一个在 Titanium Mobile SDK 1.7.5 下在 iOS 上表现相同的示例:

I've come across this as well. When adding an array to a TiProxy object (View, Window, button etc.) it doesn't work as expected. You need to manipulate the array 'off' the proxy, then re-set it. I don't know if this is a bug or just a limitation of properties on TiProxy objects. Here is an example that behaves the same on iOS under Titanium Mobile SDK 1.7.5:

var proxy = Ti.UI.createView();  //this can be any TiProxy object

proxy.someArray = [];
proxy.someArray.push( '1' );
proxy.someArray.push( '2' );
Ti.API.info("Array modified directly on TiProxy object" );
Ti.API.info(proxy.someArray );

var myArray = [];
myArray.push( '1' );
myArray.push( '2' );
proxy.someArray = myArray;
Ti.API.info("Array modified outside TiProxy object" );
Ti.API.info( proxy.someArray );

proxy.someArray.push( '3' );
Ti.API.info("This will be unchanged" );
Ti.API.info(proxy.someArray );

var changeArray = proxy.someArray;
changeArray.push('3');
proxy.someArray = changeArray;
Ti.API.info("This is how you must do it." );
Ti.API.info(proxy.someArray );

返回:

[INFO] Array modified directly on TiProxy object
[INFO] []
[INFO] Array modified outside TiProxy object
[INFO] [ 1,  2 ]
[INFO] This will be unchanged
[INFO] [ 1,  2 ]
[INFO] This is how you must do it.
[INFO] [ 1, 2, 3 ]

找出 Android 上的行为要困难得多,因为 Ti.API.info(proxy.someArray); 只返回一个对象引用.

Finding out the behavour on Android is a lot harder bacause Ti.API.info(proxy.someArray ); just returns an object reference.

这篇关于使用 Titanium Appcelerator mobile 1.7.2 添加元素后的空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆