Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3216] Android: Expose Properties Dictionary

GitHub Issuen/a
TypeNew Feature
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:01:12.000+0000
Affected Version/sn/a
Fix Version/sSprint-2011-09
ComponentsAndroid
Labelsandroid, feature, release-1.7.0, reported-1.6.0, rplist
ReporterDawson Toth
AssigneeDon Thorp
Created2011-04-15T03:39:41.000+0000
Updated2011-04-17T02:01:12.000+0000

Description

Problem

Object.keys and for X in Y should work for proxy objects. Right now you can't do for (var n in Ti.UI.createWindow({ left: 0, right: 0 }) {}, for example.

Example App

var win = Ti.UI.createWindow({ backgroundColor: '#fff', title: 'Test' });
win.color = '#444';
var label = Ti.UI.createLabel({ left: 20, right: 20 });
win.add(label);
win.open();

label.text = '';
for (var n in win) {
    label.text += n + ': ' + win[n] + ',\n';
}
if (label.text.length == 0) {
    label.text = 'FAIL: We were not able to iterate over the properties of the proxy object using for-in!';
}

The label.text will contain a line for each property.

Tested On

Titanium SDK version: 1.7.0 (02/18/11 18:13 316c2c7)
BROKEN in iPhone Simulator 4.2
BROKEN on Android EPIC 4g Device 2.1

Associated Helpdesk Ticket

http://developer.appcelerator.com/helpdesk/view/75581">http://developer.appcelerator.com/helpdesk/view/75581

Comments

  1. Marshall Culpepper 2011-04-15

    (from [5d8c78a437289743b62125b34634862775fcff05]) initial support of for (x in proxy) and Object.keys(proxy).forEach in Android [#3216 state:fixed-in-qa milestone:Sprint-2011-09]
    https://github.com/appcelerator/titanium_mobile/commit/5d8c78a437289743b62125b34634862775fcff05"> https://github.com/appcelerator/titanium_mobile/commit/5d8c78a43728...

  2. Marshall Culpepper 2011-04-15

    Updated to test both Object.keys and Object.getOwnPropertyNames:

       
       var win = Ti.UI.createWindow({ backgroundColor: '#fff', title: 'Test' });
       var label = Ti.UI.createLabel({ top: 20, left: 20, right: 20, text: '' });
       win.add(label);
       
       
       for (var n in win) {
           label.text += n + ': ' + win[n] + ',\n';
       }
       if (label.text.length == 0) {
           label.text = 'FAIL: We were not able to iterate over the properties of the proxy object using for-in!';
       }
       
       var label2 = Ti.UI.createLabel({ top: 20, left: 20, right: 20, text: ''});
       win.add(label2);
       
       Object.keys(win).forEach(function(key) {
           label2.text += key + ': ' + win[key]+ ',\n';
       });
       
       if (label2.text.length == 0) {
           label2.text = 'FAIL: We were not able to iterate over the properties of the proxy object using Object.keys(proxy).forEach!';
       }
       
       var label3 = Ti.UI.createLabel({ top: 20, left: 20, right: 20, text: ''});
       win.add(label3);
       
       Object.getOwnPropertyNames(win).forEach(function(key) {
           label3.text += key + ', '
       });
       
       if (label3.text.length == 0) {
           label3.text = 'FAIL: We were not able to iterate over the properties of the proxy object using Object.getOwnPropertyNames(proxy).forEach!';
       }
       
       win.open();
       
  3. Natalie Huynh 2011-04-15

    Tested with Titanium SDK version: 1.7.0 (03/03/11 11:06 87a2113) on
    Emulator 2.1
    Galaxy Tab 2.2

    Still broken on iPhone 4 OS 4.2.1 and Emulator

  4. Don Thorp 2011-04-15

    Created #3299 to track the iOS side of this problem. Marking this one as resolved per Natalie's comment. Adding the release 1.7.0 tag back it got removed.

JSON Source