Are there any consequences of evaluating data in underscore micro templates?
for instance if we say we have this in our javascript file:
this.template({a: '10'});
And in our html template file
<%= a > 5 ? 'Val is larger than 5':'Val is smaller than 5' %>
Would it be better not to evaluate the data in the template?
答案 0 :(得分:1)
不是分离问题吗?你在一个表达的“层”中注入逻辑,在我看来,潜在的错误将更难以跟踪。
您的示例很简单,但想象一下您有类似
的情况 <%= a > 10 ? (b > 20 ? " and b greater than 20" : " and b less than 20") : ( c > 20 ? " and c greater than 20" : " and c less than 20") %>
根本不可读。