How do I lowercase a field using Handlebars.js?

前端 未结 5 1073
我寻月下人不归
我寻月下人不归 2021-02-01 14:27

I want to do something like this:

{{user.name.toLowerCase()}}

but I get this error:

Error: Parse error on line X:
...tatus {{us         


        
5条回答
  •  既然无缘
    2021-02-01 14:35

    I created the following helper, but I'm curious if there's a better solution out there.

    Handlebars.registerHelper('toLowerCase', function(value) {
        if(object) {
            return new Handlebars.SafeString(value.toLowerCase());
        } else {
            return '';
        }
    });
    

提交回复
热议问题