[Mapbender-dev] Re: [Mapbender] #120: replace [...] with dot notation in JS
#120: replace [...] with dot notation in JS --+- Reporter: christoph| Owner: mapbender_dev@lists.osgeo.org Type: refactoring | Status: new Priority: major| Milestone: 2.5 release Component: core | Version: Resolution: |Keywords: --+- Comment (by christoph): 1. correct. I tried converting the map object to JSON via toJSONString(), and the entries for the arrays created with the bracket syntax were omitted. I had to use the dot syntax. Now I realize why JSLint always complains about the bracket syntax. 2. I mean the anyObject.toJSONString from json.js, which itself is from www.json.org -- Ticket URL: http://trac.osgeo.org/mapbender/ticket/120#comment:2 Mapbender http://www.mapbender.org/ Mapbender___ Mapbender_dev mailing list Mapbender_dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapbender_dev
Re: [Mapbender-dev] Re: [Mapbender] #120: replace [...] with dot notation in JS
Hey Christoph, this example works like a charm: var c = {}; // object var d = {}; // object c.test = testvalue; // dot on object d[test] = testvalue; // parens on object alert( c.toJSONString() ); // alerts: {test : testvalue} alert( c.toJSONString() === '{test:testvalue}' ); // alerts: true alert( d.toJSONString() ); // alerts: {test : testvalue} alert( d.toJSONString() === '{test:testvalue}' ); // alerts: true alert( c.toJSONString() === d.toJSONString() ); // alerts: true Can you post a minimal example that fails? Maybe it isn't the toJSONString()-method that is the root of this error. -- Marc Mapbender schrieb: #120: replace [...] with dot notation in JS --+- Reporter: christoph| Owner: mapbender_dev@lists.osgeo.org Type: refactoring | Status: new Priority: major| Milestone: 2.5 release Component: core | Version: Resolution: |Keywords: --+- Comment (by christoph): 1. correct. I tried converting the map object to JSON via toJSONString(), and the entries for the arrays created with the bracket syntax were omitted. I had to use the dot syntax. Now I realize why JSLint always complains about the bracket syntax. 2. I mean the anyObject.toJSONString from json.js, which itself is from www.json.org ___ Mapbender_dev mailing list Mapbender_dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapbender_dev ___ Mapbender_dev mailing list Mapbender_dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapbender_dev
Re: [Mapbender-dev] Re: [Mapbender] #120: replace [...] with dot notation in JS
Sorry for the last post. Ignore it. Too much copy and paste for any human to handle. Here's the version I intended to post -- To illustrate the difference, an example Does not work with toJSONString() currentLayer.layer_style[count] = []; currentLayer.layer_style[count][name] = styleName; currentLayer.layer_style[count][title] = styleTitle; currentLayer.layer_style[count][legendurl] = styleLegendUrl; currentLayer.layer_style[count][legendurlformat] = styleLegendUrlFormat; Does work currentLayer.layer_style[count] = {}; currentLayer.layer_style[count].name = styleName; currentLayer.layer_style[count].title = styleTitle; currentLayer.layer_style[count].legendurl = styleLegendUrl; currentLayer.layer_style[count].legendurlformat = styleLegendUrlFormat; May work, not tried (curly brackets in line 1) currentLayer.layer_style[count] = {}; currentLayer.layer_style[count][name] = styleName; currentLayer.layer_style[count][title] = styleTitle; currentLayer.layer_style[count][legendurl] = styleLegendUrl; currentLayer.layer_style[count][legendurlformat] = styleLegendUrlFormat; ___ Mapbender_dev mailing list Mapbender_dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapbender_dev