2012-06-08 109 views
3

的小於條件(如果)語句返回這個瀏覽器錯誤:「未捕獲類型錯誤:對象46具有沒有方法‘替換’」在上線463的jsrender.js文件(在瀏覽器和IE8)JSRender條件語句

**更新2012-06-10 ---對不起,在我原來的文章中,我簡化了我的場景太多,錯誤不在那裏。我更新了代碼(以下)以更準確地表示我看到的錯誤。如果您從該代碼中刪除了{{if 1 == 1}}行,它將完美無瑕地運行。這條線完好無損,我得到了上述錯誤。

<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> 
+0

您是否有具體問題或者您是否提交了錯誤報告? –

+0

在Chrome(19.0.1084.52)中適合我:http://jsfiddle.net/yJV4y/1/ jQuery 1.7.2,jsrender v1.0pre。 –

+0

以上工作對我來說也很好。 – BorisMoore

回答

2

抱歉,沒有看到您的更新。 關閉if標籤有額外的空白。它應該是{{/if}},而不是{{/if }}