PDA

View Full Version : How to define an object in Component Config



joe_montanab
11 Feb 2012, 1:44 PM
I'm currently using an Ext.Map view, but this applies to any view really. In the component config area for Ext.Map there is a mapOptions setting. The text for the value shows [object]..., when I click on it I get a blank box. I try to add my object in there and it sets my value as a quoted string in code view.

What I put in:

{ centered: 45.622469,-122.666933 }

What I expect to show up in code view:



...
config: {
mapOptions: { centered: 45.622469,-122.666933 }
}
...


But here is what I actually get:



...
config: {
mapOptions: '{ centered: 45.622469,-122.666933 }\n'
}
...


How can I set the value for mapOptions (or any object in the component config area) and have it take it as an object instead of a literal string?

Thanks!
-Joe

bharatn
11 Feb 2012, 7:25 PM
Thats not a valid object

needs to be { prop: value, prop1: value}

Look at this
http://code.google.com/apis/maps/documentation/javascript/reference.html#MapOptions

This is one way to specify an object but the center expects a reference and we dont support reference in Designer currently so you will need to add custom code in impl class.

{
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

jnw
14 Feb 2012, 12:10 PM
Did you figure out how to implement this? I'm stuck on the same exact problem.



I'm currently using an Ext.Map view, but this applies to any view really. In the component config area for Ext.Map there is a mapOptions setting. The text for the value shows [object]..., when I click on it I get a blank box. I try to add my object in there and it sets my value as a quoted string in code view.

What I put in:

{ centered: 45.622469,-122.666933 }

What I expect to show up in code view:



...
config: {
mapOptions: { centered: 45.622469,-122.666933 }
}
...


But here is what I actually get:



...
config: {
mapOptions: '{ centered: 45.622469,-122.666933 }\n'
}
...


How can I set the value for mapOptions (or any object in the component config area) and have it take it as an object instead of a literal string?

Thanks!
-Joe

joe_montanab
14 Feb 2012, 12:25 PM
Did you figure out how to implement this? I'm stuck on the same exact problem.

I did- the problem was that I had a syntax error in my object definition. I figured out that if there is an object value and you actually type in a proper object it works fine and auto-generates the object in your code, but if you make a syntax error it turns it into a string instead.

So, flip to code view and make sure you didn't mess up the syntax anywhere, you'll see it create an object or string based on what you type in.

jnw
14 Feb 2012, 1:01 PM
Ahh, I see. Thanks! For some reason it doesn't like mapTypeId though. The other mapOptions seem to work as you described.