首页 > 解决方案 > 如何在 rivetsJS 中使用 OR 条件

问题描述

如何在 rivetsJS 中使用 OR 条件,同时在 html dom 中绑定它。使用铆钉时,以下代码对我不起作用。当我使用单个条件时它有效

<div rv-class-highlight="view.year || view.month">
</div>

标签: javascriptrivets.js

解决方案


我一直在使用格式化程序

rivets.formatters.or = function(value, args) {
  return value || args;
};

接着

<div rv-class-highlight="view.year | or view.month">
</div>

推荐阅读