underscore template
에서 mustache.js
으로 변경하고 싶습니다.에서 밑줄 템플릿까지 mustache.js
mustache.js에는 if statements
이 없으므로 mustache.js
을 사용하려면 어떻게해야합니까?
<% if (done) { %>
<span class="todo-clear">
<a href="#">
Clear <span class="number-done"><%= done %></span>
completed <span class="word-done"><%= done === 1 ? 'item' : 'items' %></span>
</a>
</span>
<% } %>
내 솔루션은 다음과 같습니다
{{#total}}
<span class="todo-count">{{ total }}
<span class="number">{{ remaining }}</span>
<span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left.-->
</span>
<span class="hint">
Drag tasks from one list into another and vice versa.
</span>
{{/total}}
가 0 이상이 될 수 있기 때문에 그것은, 총 변수 작동하지만, 변수를 나머지에 문제를 해결하는 가장 좋은 방법이 무엇인지 모른다있는 1 이상일 수 있습니다.
<span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left.</span>
그것은 그런 일해야한다 :
<span class="word">
{{#remaining}} 'items' {{/remaining}}
{{^remaining}} 'item' {{/remaining}}
</span>
남아있는 1 이상으로 할 수 있기 때문에 그것은 작동하지 않습니다. 보기에
을'statements' 이런 방식으로 작동하는 경우 : 인수가 거짓 정의되지 않은, null를 돌려줍니다 경우 또는 [] (는 "falsy"값) ,'Handlebars'는 블록을 렌더링하지 않습니다. 그러나 이것은 콧수염에'{{#total}}'과'{{^ total}} '을 만드는 것과 같습니다. – underscore666