Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSRender conditional statement

The below conditional (if) statement is returning this browser error: "Uncaught TypeError: Object 46 has no method 'replace'" in the jsrender.js file on line 463 (in Chrome and IE8)

**Update 2012-06-10---Sorry, in my original post, I'd simplified my scenario too much, and the error wasn't there. I've updated the code (below) to more accurately represent the error I'm seeing. If you remove the {{if 1==1}} line from this code, it runs flawlessly. With this line intact, I get the above-mentioned error.

<script id="tmpl_report_entry_table_data_rows" type="text/x-jsrender">
    {{if 1==1}}
    <tr class="attribute_data_row">
        <td class="entry_id attribute_data"><span>{{:ENTRY_ID}}</span></td>
        <td class="attribute_1 attribute_data hidden"><span>{{:ATTRIBUTE__1}}</span></td>
        <td class="attribute_2 attribute_data"><span>{{:ATTRIBUTE__2}}</span></td>
        <td class="attribute_14 attribute_data"><span>{{:ATTRIBUTE__14}}</span></td>
        <td class="attribute_13 attribute_data"><span>{{:ATTRIBUTE__13}}</span></td>
        <td class="attribute_11 attribute_date attribute_data"><span>{{:ATTRIBUTE__11}}</span></td>
        <td class="attribute_11 attribute_date_hidden"><span>{{:ATTRIBUTE__11}}</span></td>
        <td class="attribute_3 attribute_data"><span>{{:ATTRIBUTE__3}}</span></td>
        <td class="attribute_4 attribute_data"><span>{{:ATTRIBUTE__4}}</span></td>
        <td class="attribute_5 attribute_data">
            <a href="?"><span>{{:ATTRIBUTE__5}}</span></a>
        </td>
        <td class="cmd"></td>
    </tr>    
    {{/if }}
</script>

<script>
    var obj_my_data = [
        {"ENTRY_ID":79,
            "test":true,
            "ATTRIBUTE__1":"Aleutian Islands",
            "ATTRIBUTE__2":"Arrowtooth Flounder",
            "ATTRIBUTE__13":"BSAI trawl limited access",
            "ATTRIBUTE__3":"Open",
        "ATTRIBUTE__4":"TAC",
        "ATTRIBUTE__5":"",
        "ATTRIBUTE__11":",",
        "ATTRIBUTE__14":"Entire GOA"},
        {"ENTRY_ID":80,
        "test":true,
        "ATTRIBUTE__1":"Aleutian Islands",
        "ATTRIBUTE__2":"Atka Macherel",
        "ATTRIBUTE__13":"BSAI trawl limited access",
        "ATTRIBUTE__3":"Open",
        "ATTRIBUTE__4":"TAC",
        "ATTRIBUTE__5":"",
        "ATTRIBUTE__11":",",
        "ATTRIBUTE__14":"Entire GOA"}
    ];

    $(document).ready(function(){  
        $("table tbody").append($("#my_template").render(obj_my_data)); 
    });
</script>
like image 605
Octavient Avatar asked Jan 22 '26 14:01

Octavient


1 Answers

Sorry didn't see your update. The closing if tag has extra white space. It should be {{/if}}, not {{/if }}.

like image 193
BorisMoore Avatar answered Jan 25 '26 03:01

BorisMoore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!