从自定义helper调用Handlebars if helper
Calling Handlebars if helper from a custom helper
我正在寻找一种方法来覆盖车把中的"if"帮助器来进行预处理,但随后调用原始的if帮助器来完成其余的繁重工作。
如果我这样做,它会建立一个无限循环:
// objectCreate is just a function that's supposed to clone an object.
Handlebars._helpers = objectCreate(Handlebars.helpers);
Handlebars.registerHelper('if', function(conditional, options){
console.log("if helper");
conditional = false;
Handlebars._helpers["if"].call(this, conditional, options)
});
有人曾经这样做过吗?我知道我可以做一个自定义的助手,如"conIf",然后调用原来的,但我想保持相同的名称,如果可能的话。
谢谢你的帮助!
终于找到了:
Handlebars._helpers = {};
// This is what somehow breaks the pointer and stops it from forever looping.
for(var i in Handlebars.helpers){
Handlebars._helpers[i] = Handlebars.helpers[i];
}
Handlebars.registerHelper('if', function(conditional, options){
return Handlebars._helpers["if"].call(Handlebars, conditional, options);
});
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如果 a 为 false,则 if(a) === if(false)
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- 正在尝试使用if和else添加类,但无法正常工作
- 在PHP中使用javascript更改页面标题'if'
- gulp-if-javascript文件,但不在gulp-useref的特定目录中
- 如何在 API 调用后和 if 语句中启用提交按钮
- 带有多个elseif的Javascript if语句
- 什么是&&在没有if的行中的变量之间
- 另一个if(!$scope.$$phase)$scope$apply()szenario-需要帮助才能通关
- Sharepoint JScript if语句未执行
- Javascript:If-then语句在函数中不起作用
- for循环中的javascript if语句找不到==
- Handlerbars.js在#if语句中使用helper函数
- 将Handlebars helper作为参数传递给#if
- 我想在Ember.Handlebars.helper中加入Handlebar {{#if}}逻辑
- Ember js使用{{#if}} helper来切换显示的动态动作
- 从自定义helper调用Handlebars if helper
- 在Handlebars模板中的If块内调用Helper