Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

javascript - How do I lowercase a field using Handlebars.js?

I want to do something like this:

{{user.name.toLowerCase()}}

but I get this error:

Error: Parse error on line X:
...tatus {{user.name.toLowerCase()}}">  
-----------------------^
Expecting 'ID', got 'undefined'
question from:https://stackoverflow.com/questions/9011228/how-do-i-lowercase-a-field-using-handlebars-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As simply explained in the doc :

Handlebars.registerHelper('toLowerCase', function(str) {
  return str.toLowerCase();
});

And just use it like this :

<h1>By {{toLowerCase author}}</h1>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...