은 분명히, jQuery를 템플릿을 컴파일 할 수 있으며이 here을 보여 문 경우와 템플릿의 성능을하는 데 도움이됩니다.
그러나 표시된대로 here, 내 템플릿에는 논리 블록이 없으므로 미리 컴파일 된 jQuery 템플릿은 제 경우에는별로 도움이되지 않습니다.
다른 템플릿 엔진의 사용을 제안하는 사람들에게는 jQuery 템플릿 만 사용하는 것이 좋습니다. 팀의 모든 사람이 jQuery를 알고 있기 때문입니다. 몇 가지 템플릿 엔진을 비교하는 this 테스트 케이스도 있습니다.
안녕
,그냥 오늘은 내가 jQuery를 템플릿을 사용하여 성능 문제가 있다는 것을 들었다.
비교하려면 jQuery 템플릿과 좋은 이전 문자열 append 메서드를 사용하여 테이블에 행을 추가했습니다. 결과는 here으로 볼 수 있습니다. jQuery 템플릿을 사용하면 문자열 추가 메서드와 비교할 때 약 65 % 느려집니다.
jQuery 템플릿 스크립트의 성능을 향상시키기 위해 수행 할 수있는 작업이 궁금합니다.
전체 스크립트는 제공된 링크에서 볼 수 있습니다. 그러나 기본 개념은 다음과 같다 :
템플릿 :
<script type="x-jquery-tmpl" id="tmplRow">
<tr>
<td><input type="checkbox" value="${id}" /></td>
<td>${firstName} ${lastName}</td>
<td class="edit">
<a>Edit</a>
<input style="display:none;" type="hidden" value="Blah" />
<input class="cancel" type="button" value="cancel" />
</td>
<td class="select">
<a>Select</a>
<select style="display:none;">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
<input class="cancel" type="button" value="cancel" />
</td>
<td>More string</td>
<td>More string</td>
<td>More string</td>
<td>More string</td>
<td>More string</td>
<td>More string</td>
</tr>
</script>
데이터 :
<script type="text/javascript">
var data = [];
for (var i = 0; i < 100; i++) {
var row = {
id: i,
firstName: 'john',
lastName: 'doe'
};
data.push(row);
}
</script>
HTML :
<table id="table"></table>
가 실행 :
<script type="text/javascript">
$('#tmplRow').tmpl(data).appendTo('#table');
</script>
,451,515,
감사합니다,
치
나는 핸들을 확인하기 위해 상관하지 않습니다. 그러나 다운로드가 작동하지 않습니다. 소스에서 "handlebars.js"만 참조하면 정의되지 않은 "required"메소드가 실패합니다. js 파일 복사본이 있습니까? –
jquery templates가 템플릿을 '컴파일'합니다 ... – user406905
템플릿을 컴파일하는 것만으로도 논리 제어 블록이있는 경우에만 도움이됩니다. 자세한 내용은 업데이트 된 질문을 확인하십시오. –