JSRender loses value in for loop

  • Why does the value inside the for loop produce no result while the one outside does ???

    value:{{:~value}} <---produces a value

    {{for ~range(25)}}
    value:{{:value}} <--- produces no result

  • well there is different context inside the loop

    in your case I believe you want to use value: {{:#data}} , but I recommend to check jsrender docs

  • Sorry Jan, you need more context.

    The loop is in a child template, full contents are

    value:{{:value}} <-- this produces value
    	<div class="header-text pull-right">
    	{{if value == 0}}
            <p> {{:value2}}</p>
    		<table class="risk-rating">
    			<tr class="gradient">
    			    {{for ~range(25)}}
    			    value:{{:value}} <-- this does not
    	                <td class="r{{>#data + 1}} {{if value == (#data + 1)}} active{{/if}}"></td> <---This if is my goal

    it's being invoked by

    	{#child V2-Asset-Score-Indicator @data.RiskScore={{:RiskScore}} @data.RiskDescription={{:FullRiskDescription}} @template.engine=jsrender @template.recipe=html @options.language=sp}

  • Hm. I think my answer still applies. If you run for loop. The current context is the element in the array.
    Check the jsrender documentation how to access the parent context.

  • Thanks, Jan. using {{if #parent.parent.data.value == (#data + 1)}} worked

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.