Example of using Handlebars lookup helper

后端 未结 2 1423
耶瑟儿~
耶瑟儿~ 2021-01-07 17:07

Handlebars has a built-in helper called lookup. The documentation is not very clear about how it works. Could I see an example?

2条回答
  •  终归单人心
    2021-01-07 17:17

    Sure, past me! Here's an example from your future.

    Suppose you have an object or array obj and a variable field and you want to output the value of obj[field], you would use the lookup helper {{lookup obj field}}.

    The code defining the helper is simply:

    function(obj, field) {
      return obj && obj[field];
    }
    

提交回复
热议问题