在 underscore.js 微模板中评估数据的错误做法?
Bad practice to evaluate data in underscore.js micro template?
评估下划线微模板中的数据有任何后果吗?
例如,如果我们说我们的 javascript 文件中有这个:
this.template({a: '10'});
并且在我们的 html 模板文件中
<%= a > 5 ? 'Val is larger than 5':'Val is smaller than 5' %>
不评估模板中的数据会更好吗?
不是关注点分离的问题吗?您正在演示中注入逻辑 "layer",我认为潜在的错误将更难追踪。
你的例子很简单,但想象一下你有类似
的场景
<%= 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") %>
根本不可读。
评估下划线微模板中的数据有任何后果吗?
例如,如果我们说我们的 javascript 文件中有这个:
this.template({a: '10'});
并且在我们的 html 模板文件中
<%= a > 5 ? 'Val is larger than 5':'Val is smaller than 5' %>
不评估模板中的数据会更好吗?
不是关注点分离的问题吗?您正在演示中注入逻辑 "layer",我认为潜在的错误将更难追踪。
你的例子很简单,但想象一下你有类似
的场景<%= 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") %>
根本不可读。