Is it possible to use function in Handlebars #if?

后端 未结 4 1806
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 13:37

I have a controller object that\'s like:

MyApp.objController = Ember.ArrayController.create({
  init: function(data) {
    data.isValid = function() {
      retu         


        
4条回答
  •  忘了有多久
    2021-02-05 14:14

    If you define your isValid as a property, you can use it in your if statement without creating a custom Handlebars helper, see http://jsfiddle.net/pangratz666/Dq6ZY/:

    Handlebars:

    JavaScript:

    App.MyObj = Ember.Object.extend({
        isValid: function() {
            return this.get('age') >= 18;
        }.property('age')
    });
    
    Ember.View.create({
        templateName: 'obj-template',
        controller: App.MyObj.create({
            age: 21
        })
    }).append();
    

提交回复
热议问题