|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
converting qx.core.Object to mapHi, what is the best way of converting a qx.core.Object instance into a map containing its properties' keys and values? Of course, one can easily do var json = qx.util.Serializer.toJson( myQxCoreObjectInstance ); var map = qx.util.Json.parse( json ); but that appears to be wasteful. I wonder if a toMap() method would be a good addition to the qx.core.Object class. Thanks, C. -- View this message in context: http://n2.nabble.com/converting-qx-core-Object-to-map-tp3902297p3902297.html Sent from the qooxdoo mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
|
|
Re: converting qx.core.Object to mapOn Tue, Oct 27, 2009 at 18:43, panyasan <info@...> wrote:
If all you want is properties, it looks like you can do it like this: http://demo.qooxdoo.org/current/playground/#%7B%22code%22%3A%20%22var%2520clazz%2520%253D%2520qx.ui.table.Table%253B%250A%250Avar%2520list%2520%253D%2520qx.Class.getProperties%28clazz%29%253B%250Avar%2520map%2520%253D%2520%257B%257D%253B%250A%250Afor%2520%28var%2520i%2520%253D%25200%253B%2520i%2520%253C%2520list.length%253B%2520i%252B%252B%29%250A%257B%250A%2520%2520map%255Blist%255Bi%255D%255D%2520%253D%2520qx.Class.getPropertyDefinition%28clazz%252C%2520list%255Bi%255D%29%253B%250A%2520%2520this.debug%28list%255Bi%255D%2520%252B%2520%2522%253A%2520%2522%2520%252B%2520qx.Class.getPropertyDefinition%28clazz%252C%2520list%255Bi%255D%29%29%253B%250A%257D%250A%250A%250A%22%7D Derrell ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
|
|
Re: converting qx.core.Object to map
Derrell,
I just had to try the Playground code for the first time, and that's really neat! But, doesn't your code just provide a list of the properties names for a given class, rather than the properties and values of an instance of a class? I think that's what he was looking to get in the map output. You know, like: allowShrinkY:true allowShrinkX:false etc. Gene On Tue, 2009-10-27 at 22:44 -0400, Derrell Lipman wrote: On Tue, Oct 27, 2009 at 18:43, panyasan <info@...> wrote: ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
|
|
Re: converting qx.core.Object to mapTake a look at the "map" variable in Darrell's example.
That is what you are interested in Gene Amtower wrote: > Derrell, > > I just had to try the Playground code for the first time, and that's > really neat! But, doesn't your code just provide a list of the > properties names for a given class, rather than the properties and > values of an instance of a class? I think that's what he was looking to > get in the map output. > > You know, like: > > allowShrinkY:true > allowShrinkX:false > etc. > > Gene > > On Tue, 2009-10-27 at 22:44 -0400, Derrell Lipman wrote: >> On Tue, Oct 27, 2009 at 18:43, panyasan <info@... >> <mailto:info@...>> wrote: >> >> >> Hi, >> >> what is the best way of converting a qx.core.Object instance into >> a map >> containing its properties' keys and values? Of course, one can >> easily do >> >> var json = qx.util.Serializer.toJson( myQxCoreObjectInstance ); >> var map = qx.util.Json.parse( json ); >> >> but that appears to be wasteful. I wonder if a toMap() method >> would be a >> good addition to the qx.core.Object class. >> >> >> If all you want is properties, it looks like you can do it like this: >> >> http://demo.qooxdoo.org/current/playground/#%7B%22code%22%3A%20%22var%2520clazz%2520%253D%2520qx.ui.table.Table%253B%250A%250Avar%2520list%2520%253D%2520qx.Class.getProperties%28clazz%29%253B%250Avar%2520map%2520%253D%2520%257B%257D%253B%250A%250Afor%2520%28var%2520i%2520%253D%25200%253B%2520i%2520%253C%2520list.length%253B%2520i%252B%252B%29%250A%257B%250A%2520%2520map%255Blist%255Bi%255D%255D%2520%253D%2520qx.Class.getPropertyDefinition%28clazz%252C%2520list%255Bi%255D%29%253B%250A%2520%2520this.debug%28list%255Bi%255D%2520%252B%2520%2522%253A%2520%2522%2520%252B%2520qx.Class.getPropertyDefinition%28clazz%252C%2520list%255Bi%255D%29%29%253B%250A%257D%250A%250A%250A%22%7D >> >> >> Derrell >> >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... <mailto:qooxdoo-devel@...> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > > > ------------------------------------------------------------------------ > > _______________________________________________ > qooxdoo-devel mailing list > qooxdoo-devel@... > https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
|
|
Re: converting qx.core.Object to mapOn Tue, Oct 27, 2009 at 23:23, Gene Amtower <gene@...> wrote:
Well I am enumerating the values of the properties, but you're right that what I've done may not be what Christian is looking for. Since these functions take a class as parameter rather than an instance, they can't possibly provide a particular instance's property values. Maybe the inside of the loop should contain calls akin to this: var propGet = "myObjectInstance.get" + upperFirstChar(list[i]) + "()"; map[list[i]] = eval(propGet); There is a method someplace that converts the first character to upper case, what the above upperFirstChar() does. I think it's used in qx/Class.js or qx/core/Property.js, but since I don't have the qooxdoo source in front of me, I can't currently provide details. Derrell ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
|
|
Re: converting qx.core.Object to mapeval is evil! Also it won't work for grouped properties.
I've modified Derrells example, hopefully this is what you want: http://demo.qooxdoo.org/current/playground/#%7B%22code%22%3A%20%22function%2520getProperties%28object%29%250A%257B%250A%2520%2520var%2520clazz%2520%253D%2520object.constructor%253B%250A%2520%2520var%2520list%2520%2520%253D%2520qx.Class.getProperties%28clazz%29%253B%250A%2520%2520var%2520map%2520%2520%2520%253D%2520%257B%257D%253B%250A%2520%2520%250A%2520%2520for%2520%28var%2520i%2520%253D%25200%252C%2520l%2520%253D%2520list.length%253B%2520i%2520%253C%2520l%253B%2520i%252B%252B%29%250A%2520%2520%257B%250A%2520%2520%2520%2520if%2520%28!qx.Class.getPropertyDefinition%28clazz%252C%2520list%255Bi%255D%29.group%29%250A%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520map%255Blist%255Bi%255D%255D%2520%253D%2520object.get%28list%255Bi%255D%29%250A%2520%2520%2520%2520%2520%257D%250A%2520%2520%257D%250A%2520%2520return%2520map%253B%250A%257D%250A%250Avar%2520btn%2520%253D%2520new%2520qx.ui.form.Button%28%2522test%2522%29%253B%250Avar%2520properties%2520%253D%2520getProperti es%28btn%29%250Athis.debug%28qx.util.Json.stringify%28properties%252Ctrue%29%29%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520%250A%250A%22%7D function getProperties(object) { var clazz = object.constructor; var list = qx.Class.getProperties(clazz); var map = {}; for (var i = 0, l = list.length; i < l; i++) { if (!qx.Class.getPropertyDefinition(clazz, list[i]).group) { map[list[i]] = object.get(list[i]) } } return map; } var btn = new qx.ui.form.Button("test"); var properties = getProperties(btn); this.debug(qx.util.Json.stringify(properties,true)); HTH, Matt Derrell Lipman wrote: > On Tue, Oct 27, 2009 at 23:23, Gene Amtower <gene@... > <mailto:gene@...>> wrote: > > Derrell, > > I just had to try the Playground code for the first time, and that's > really neat! But, doesn't your code just provide a list of the > properties names for a given class, rather than the properties and > values of an instance of a class? I think that's what he was > looking to get in the map output. > > You know, like: > > allowShrinkY:true > allowShrinkX:false > etc. > > Well I am enumerating the values of the properties, but you're right > that what I've done may not be what Christian is looking for. Since > these functions take a class as parameter rather than an instance, they > can't possibly provide a particular instance's property values. Maybe > the inside of the loop should contain calls akin to this: > > var propGet = "myObjectInstance.get" + upperFirstChar(list[i]) + "()"; > map[list[i]] = eval(propGet); > > There is a method someplace that converts the first character to upper > case, what the above upperFirstChar() does. I think it's used in > qx/Class.js or qx/core/Property.js, but since I don't have the qooxdoo > source in front of me, I can't currently provide details. > > Derrell > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > > > ------------------------------------------------------------------------ > > _______________________________________________ > qooxdoo-devel mailing list > qooxdoo-devel@... > https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
|
|
Re: converting qx.core.Object to mapOn Wed, Oct 28, 2009 at 07:46, Matthew Gregory <matthew%2Bqooxdoo@...> wrote:
eval is evil! From a purist point of view, yes. In this case, there was no human input involved, so it isn't actually evil. However: I've modified Derrells example, hopefully this is what you want: Although the playground app doesn't present anything, I like your solution much better. D ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@... https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel |
| Free embeddable forum powered by Nabble | Forum Help |