Writing a helper that produces bound results?

前端 未结 3 1749
忘掉有多难
忘掉有多难 2020-12-09 18:31

I have a date/time formatting helper but what it produces does not update when the underlying property changes. This is not a surprise, but does anyone know how to produce

3条回答
  •  -上瘾入骨i
    2020-12-09 19:14

    It is now possible to create bound Handlebars helpers using a public Ember API.

    Handlebars.registerBoundHelper('timestamp', function(date, options) {
      var formatter        = options.hash['format'] ? options.hash['format'] : 'hh:mm a MM-DD-YYYY';
      var parsed_date      = moment(date);
      var formatted_date   = parsed_date.format(formatter);
    
      return new Handlebars.SafeString("");
    });
    

    The parameter passed to the helper will have already been resolved, and the helper will be called again whenever the path changes.

提交回复
热议问题