想要从 json 获取单个值并使用 handlebars.js 为其添加徽章

Want to get a single value from json and add a badge to it using handlebars.js

json数据示例:

data: [
    {name: "brian", product: "computers"},
    {name: "tom", product: "computers"},
    {name: "john", product: "computers"},
    {name: "sara", product: "machines"}
]

我想在具有 "machines" 作为产品值的用户旁边显示图像(徽章)。我将如何在车把中做到这一点?

我解决了我自己的问题,但如果有人有更好的方法。请补充。

车把助手:

  Handlebars.registerHelper('getBadges',function(product){
  var htmlVal = '';
  if(product === "machines") {
    htmlVal = '<span class="machines"><img src="../html/badge_icons/machines-small.png" alt="machines" style="width:30px; height:15px; border:none"></span>';
  } 
  return htmlVal;
});

html:

{{{getBadges product}}}