Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Object Attributes are Read Only?

Given the sample code here: http://pastie.org/880442

I am trying to figure out if I have a basic misunderstanding of javascript, or if Ti is doing something wacky. What I am trying to do is create some additional attributes on a UI object (in this example, a View). I do this by creating the View, and then creating a new object and assigning it to view.info (on line 9).

The trouble comes in when I try to change an attribute of this info object (line 18), and the value of that attribute doesn't change (lines 32 and 34 print the same thing - the value is 0, and not 1 as it should be based on line 18).

Any thoughts on what is going on?

— asked March 22nd 2010 by Allen Firstenberg
  • 1.0.0
  • attribute
  • iphone
  • javascript
  • mobile
0 Comments

2 Answers

  • Accepted Answer

    I think Ti is doing something wacky. Or rather I think it's magic it works at all - how on earth do they do it? ;)

    However, what if you try changing the property and then resetting the whole object like this?:

    function moveView( view ){
      view.left = 100;
      view.right = 100;
      var info = view.info;
      info.moved = 1;
      view.info = info; 
    }
    

    It's not as pretty, but at least I think this will trigger Ti to update the object. However, it would seriously rock if they fixed direct property setting!

    — answered March 22nd 2010 by Jacob Waller
    permalink
    0 Comments
  • An excellent workaround, Jacob. Tho I concur about hoping this actually gets fixed.

    — answered March 24th 2010 by Allen Firstenberg
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.