2

当绑定到的对象“模型”发生更改时,不会重新评估以下绑定的 {{if}} 语句。这与我的预期和我认为的将 if 语句绑定到对象的目的相反。难道我做错了什么?

如果数据.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);
});

显示.hbs:

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

测试时,我在控制台中使用它来更新绑定对象:

App.__container__.lookup('store:main').find('post',1).then(function(model){ 
    model.set('title','mydream20'); 
    model.save(); 
});
4

0 回答 0