import
和export
是即將在下一個版本的Javascript中使用的module syntax的關鍵字。您今天可以使用它們,使用transpiler將其轉換爲正常的ES5語法。
但是,如果您只使用了一些幫助器,那麼手動「轉儲」它們非常容易。不要導出該函數,只需將它傳遞給Ember.Hanldebars.registerBoundHelper
調用即可。這裏的if-condition
幫手:
Ember.Handlebars.registerBoundHelper('if-condition', function() {
var args = [].slice.call(arguments);
var options = args.pop();
var context = (options.contexts && options.contexts[0]) || this;
if (!options.conditional) {
throw new Error("A conditional callback must be specified when using the if-condition helper");
}
// Gather all bound property names to pass in order to observe them
var properties = options.types.reduce(function(results, type, index) {
if (type === 'ID') {
results.push(args[index]);
}
return results;
}, []);
// Resolve actual values for all params to pass to the conditional callback
var normalizer = function() {
return Ember.Handlebars.resolveParams(context, args, options);
};
// This effectively makes the helper a bound helper
// NOTE: 'content' path is used so that multiple properties can be bound to using the `childProperties` argument,
// however this means that it can only be used with a controller that proxies values to the 'content' property
return Ember.Handlebars.bind.call(context, 'content', options, true, options.conditional, normalizer, properties);
});
來源
2014-06-27 10:23:03
GJK
包括JS作品,螺母使用模板中的助手,拋出一個錯誤: 「未捕獲錯誤:斷言失敗:registerBoundHelper生成傭工不支持與把手塊使用。 「 – lukkysam
我發現這個:[link](http://emberjs.jsbin.com/zelib/1/edit)。 與您的代碼非常相似。這工作正常。 – lukkysam
不幸的是,我不得不取消標記,問題得到解答。 如果我使用「registerHelper」,它們工作正常,直到屬性更改。然後,該視圖不會更新。似乎,就像我必須使用「registerBoundHelper」,但使用它,發佈的錯誤將發生。 – lukkysam