当对象'模型'时,不会重新评估以下绑定{{if}}语句。它必然会发生变化。这与我的期望相反,我认为将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}}
测试时我在控制台中使用它来更新绑定的obejct:
App.__container__.lookup('store:main').find('post',1).then(function(model){
model.set('title','mydream20');
model.save();
});