2

The following bound {{if}} statement is not reevaluated when the object 'model' it is bound to changes. This is contrary to my expectation and what I thought was the purpose of binding an if statement to an object. Am I doing something wrong?

if-data.js:

Handlebars.registerHelper("ifData", function(property, fn)
{
  var context = (fn.contexts && fn.contexts[0]) || this;
  var args    = [property];

  var canAction = function(can_args)
  {
    alert('I was called for '+can_args[0].get('id'));
    return true;
  };

   // Resolve actual values for all params to pass to the conditional callback
  var normalizer = function() {
    return Ember.Handlebars.resolveParams(context, args, fn);
  };

  return Ember.Handlebars.bind.call(context, 'content', fn, true, canAction, normalizer, args);
});

show.hbs:

{{#ifData model }}
  <h1> Showme </h1>
{{/ifData}}

When testing I am updating the bound obejct using this in the console:

App.__container__.lookup('store:main').find('post',1).then(function(model){ 
    model.set('title','mydream20'); 
    model.save(); 
});
  • try using http://emberjs.com/api/classes/Ember.Handlebars.html#method_registerBoundHelper – fanta Apr 29 '14 at 20:40
  • Why don't you use "if" helper? Could you prepare a http://emberjs.jsbin.com/ example with your specific case? – ppcano Apr 29 '14 at 20:57
  • @ppcano This helper will be part of a generic declarative auhtorization library where the user will declare rules and define a function canAction for each rule. canAction is stubbed above to simplify the example. This is why I can't use the if helper. – Andreas Sæbjørnsen Apr 29 '14 at 22:13
  • I implemented the same as a component, but I am experiencing the same problem: https://gist.github.com/digitalplaywright/882e2a8470faa70e1ac4 – Andreas Sæbjørnsen Apr 29 '14 at 22:20
  • @fanta I don't think helpers registered with registerBoundHelper take blocks. – Andreas Sæbjørnsen Apr 29 '14 at 22:21
  • Andreas is correct, bound helpers do not support block statements in Ember Handlebars. http://emberjs.com/api/classes/Ember.Handlebars.html#toc_use-with-blocks-not-supported – Kingpin2k Apr 30 '14 at 02:17

0 Answers0