2016-04-15 59 views
0

评估下划线微模板中的数据是否有任何后果?评估underscore.js微模板中数据的不良做法?

例如,如果我们说我们有这个在我们的JavaScript文件:

this.template({a: '10'}); 

而在我们的HTML模板文件

<%= a > 5 ? 'Val is larger than 5':'Val is smaller than 5' %> 

它会更好不是评估模板中的数据?

回答

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") %>

无法读取的。