Is there a ternary operator in handlebars.js?

后端 未结 4 1199
说谎
说谎 2021-01-07 19:15

In Handlebars, is there a ternary operator? I don\'t mean if else; I mean like a == true ? \"a\" : \"b\".

4条回答
  •  灰色年华
    2021-01-07 19:36

    The if helper can be used as a ternary operator by passing three arguments to it.

    In the following example, a button has a default value of "Save Changes", but when model.isSaving is true, then the value temporarily changes to Saving....

    
    

    ...alternatively, used within another helper:

    {{input type="submit" value=(if model.isSaving "Saving..." "Save Changes")}}
    

提交回复
热议问题