开发者

Reference object property 'field1' using index from {#for}

Is it possible to refer to n object property in a jTemplate {#if} by dynamically creating the property name using the index from a {#for} loop?

开发者_如何学C

Example:

{#for i = 1 to 5} 
    <tr>
        <td>
           <input type="textbox" id="thisbox_{$T.i}" value="{#if $T.log.field{$T.i} != null}...{#/if}"/>
        </td>
    </tr>
{#/for}

How can I to refer to property $T.log.field# where # is the current index from the {#for}? It obviously fails when it attempts to parse {$T.log.field{$T.i}} but I'm wondering how this can be written to work or if it's even possible.


Answered my own question:

I managed to fix this by referring to the property using reflection. I changed my {#if} statement to this:

{#if $T.log['field' + $T.i] != null} ... some code here {#/if}

Referring to the field by using ['field' + $T.i] worked as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜