interating on nested elements

5 views
Skip to first unread message

Benno Blumenthal

unread,
May 13, 2013, 3:49:22 PM5/13/13
to Pure-Unobtrusive...@googlegroups.com

So that I could have multiple pieces of JSON in the same template pulled from different places, I tried naming them so that the JSON is nested a bit

 
{"prcpstaid":{"@context":{"bb":"http://iridl.ldeo.columbia.edu/ontologies/gisuri/geobb/","cfatt":"http://iridl.ldeo.columbia.edu/ontologies/cfatt.owl#","cfatt:standard_name":{"@type":"xsd:string"},"cfatt:units":{"@type":"xsd:string"},"iridl":"http://iridl.ldeo.columbia.edu/ontologies/iridl.owl#","iridl:geoId":{"@type":"@id"},"iridl:hasDependentVariables":{"@type":"iridl:Variable"},"iridl:hasIndependentVariables":{"@container":"@list","@type":"iridl:IndependentVariable"},"iridl:hasSemantics":{"@type":"@id"},"iridl:long_name":{"@type":"xsd:string"},"iridl:name":{"@type":"xsd:string"},"iridl:value":{},"iridl:values":{},"pt":"http://iridl.ldeo.columbia.edu/ontologies/gisuri/geopt/","xsd":"http://www.w3.org/2001/XMLSchema#"},"cfatt:units":"m","iridl:hasIndependentVariables":[{"cfatt:unit
s":"ids","iridl:long_name":"station","iridl:name":"IWMO","iridl:value":"65167000"}],"iridl:name":"elev","iridl:value":"174"}}

figuring I could be explicit in the template as follows.

 
<div class="template" style="color : red">
Station ID <b><span class="prcpstaid.iridl:hasIndependentVariables iridl:value"></span></b>
</div>

 My problem is that it does not work (comes up blank instead of displaying 65167000).   Just for reference,

<div class="template" style="color : red">
Station ID <b><span class="iridl:hasIndependentVariables prcpstaid.iridl:value"></span></b>
</div>
 
does in fact pull out the 174 value, as it is supposed to, though it is not what I want (here the iridl:hasIndependentVariables class does not match the JSON, so makes no difference)

Also, if I don't do the nesting

{"@context":{"bb":"http://iridl.ldeo.columbia.edu/ontologies/gisuri/geobb/","cfatt":"http://iridl.ldeo.columbia.edu/ontologies/cfatt.owl#","cfatt:standard_name":{"@type":"xsd:string"},"cfatt:units":{"@type":"xsd:string"},"iridl":"http://iridl.ldeo.columbia.edu/ontologies/iridl.owl#","iridl:geoId":{"@type":"@id"},"iridl:hasDependentVariables":{"@type":"iridl:Variable"},"iridl:hasIndependentVariables":{"@container":"@list","@type":"iridl:IndependentVariable"},"iridl:hasSemantics":{"@type":"@id"},"iridl:long_name":{"@type":"xsd:string"},"iridl:name":{"@type":"xsd:string"},"iridl:value":{},"iridl:values":{},"pt":"http://iridl.ldeo.columbia.edu/ontologies/gisuri/geopt/","xsd":"http://www.w3.org/2001/XMLSchema#"},"cfatt:units":"m","iridl:hasIndependentVariables":[{"cfatt:unit
s":"ids","iridl:long_name":"station","iridl:name":"IWMO","iridl:value":"65167000"}],"iridl:name":"elev","iridl:value":"174"}

The following works (prints 65167000) 

<div class="template" style="color : red">
Station ID <b><span class="iridl:hasIndependentVariables iridl:value"></span></b>
</div>

So is  prcpstaid.iridl:value  only supposed to work for values and not for iteration?  Could we have "prcpstaid.iridl:hasIndependentVariables iridl:value" work as well?


Or did I miss something?

Mic (BeeBole)

unread,
May 14, 2013, 5:36:00 AM5/14/13
to Pure-Unobtrusive...@googlegroups.com
As you may imagine, it is a rather complex question to understand.

Did you try to use a directive?
They give you an abstraction level, to cleanly separate the data and the markup.

Benno Blumenthal

unread,
May 14, 2013, 4:00:18 PM5/14/13
to Pure-Unobtrusive...@googlegroups.com
I followed your suggestion to use a directive, which worked (I have underlying code which uses the pureDirective method when the JSON file loads, and uses the rel="iridl:hasJSON" to connect a json file with its PURE context).

 <a id="prcpstaid" class="prcpsta" rel="iridl:hasJSON" href="http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCDC/.GHCN/.v2beta/IWMO/%28irids:SOURCES:NOAA:NCDC:GHCN:v2beta:IWMO%401001000:ds%29//region/parameter/geoobject/.IWMO/.first/VALUE/elev/info.json"></a>
 
<script>
document.getElementById('prcpstaid').parentNode.pureDirective = {
'.myvalue' : {
  'ivar<-prcpstaid.iridl:hasIndependentVariables': {
    '.': 'ivar.iridl:value'
    }
  }
};
</script>
<div class="template" style="color : red">
Station ID <b><span class="myvalue"></span></b>
</div>

Clearly I could clean my file up if I just add some code to read directives, say 

<script language="pureDirective">
{
'.myvalue' : {
  'ivar<-prcpstaid.iridl:hasIndependentVariables': {
    '.': 'ivar.iridl:value'
    }
  }
}
</div>
<div class="template" style="color : red">
Station ID <b><span class="myvalue"></span></b>
</div>


On the other hand, I would still like auto-rendering to work

<div class="template" style="color : red">
Station ID <b><span class="prcpstaid.iridl:hasIndependentVariables iridl:value"></span></b>
</div>

 
Given that the directive works, isn't that a big clue to what is not happening in the auto-render version?

Benno

Benno Blumenthal

unread,
May 14, 2013, 4:02:48 PM5/14/13
to Pure-Unobtrusive...@googlegroups.com
Sorry, I did not close the script tag correctly


Clearly I could clean my file up if I just add some code to read directives, say 
 <a id="prcpstaid" class="prcpsta" rel="iridl:hasJSON" href="http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCDC/.GHCN/.v2beta/IWMO/%28irids:SOURCES:NOAA:NCDC:GHCN:v2beta:IWMO%401001000:ds%29//region/parameter/geoobject/.IWMO/.first/VALUE/elev/info.json"></a>
<script language="pureDirective">
{
'.myvalue' : {
   'ivar<-prcpstaid.iridl:hasIndependentVariables': {
       '.': 'ivar.iridl:value'
       }
   }
}
</script>
<div class="template" style="color : red">
Station ID <b><span class="myvalue"></span></b>
</div>



Mic (BeeBole)

unread,
May 15, 2013, 9:48:15 AM5/15/13
to Pure-Unobtrusive...@googlegroups.com
The autoRender is quite basic.
This could be a regular expression issue for parsing class names.

If you don't mind could you put a very simple HTML + CSS + JSON in a http://gist.github.com
Something like: https://gist.github.com/pure/4721220
With this I can quickly check the error, and try to fix it.

Benno Blumenthal

unread,
May 15, 2013, 4:18:17 PM5/15/13
to Pure-Unobtrusive...@googlegroups.com
OK, there is a fairly clean sample at https://gist.github.com/bennoblumenthal/5587012.
Reply all
Reply to author
Forward
0 new messages