Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1952] Custom properties in TitaniumUI components

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2013-05-02T17:59:02.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterJacek H.
AssigneeCarter Lathrop
Created2013-05-02T12:56:55.000+0000
Updated2016-03-08T07:40:53.000+0000

Description

Comments

  1. Carter Lathrop 2013-05-02

    You are not able to directly change the value of an object property, this is one caveat of using custom properties. Take for example:
       // app.js
       mywindow.userInfo = {      
         id:  1,
         name: 'John Doe',
         location: 'Neverland'
       };
       mywindow.userInfo.location = "Wonderland";
       
       alert(mywindow.userInfo.location); // still "Neverland"
       
    You cannot directly change the location value. In order to change it you must do:
       var userInfo = mywindow.userInfo;
       userInfo.location = "Wonderland";
       mywindow.userInfo = userInfo; // set the whole modified again
       
       alert(mywindow.userInfo.location); // now "Wonderland" 
       alert(mywindow.userInfo.name); // other properties still work
       
    for more information please take a look at this page: http://shikii.net/blog/custom-properties-in-titanium-windows-and-controls/ If you have any more questions, feel free to ask. Regards, Carter
  2. Jacek H. 2013-05-03

    Ok, thanks for the quick response. The behavior of the custom properties is a bit strange. I found this solution to give/set references: // app.js var userInfo = { id: 1, name: 'John Doe', location: 'Neverland' }; mywindow.getUserInfo = function() { return userInfo; } mywindow.setUserInfo = function(property, value) { userInfo[property] = value; } userInfo.location = "Wonderland"; alert(mywindow.getUserInfo().location); // "Wonderland" Regards Jacek
  3. Shak Hossain 2013-12-28

    Closing as per Jacek's update.

JSON Source