汇编助手中的TypeError

时间:2013-11-07 11:50:44

标签: javascript handlebars.js typeerror templating assemble

尽管在模板中没有使用过滤器帮助器,但TypeError阻止了组装完成。看起来options参数未被传递或传递为undefined

这是堆栈跟踪:

Warning: Cannot read property 'data' of undefined Use --force to continue.
TypeError: Cannot read property 'data' of undefined
    at Object.helpers.filter (/home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars-helpers/lib/helpers/helpers-collections.js:357:15)
    at Object.eval (eval at <anonymous> (/home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/compiler/compiler.js:564:23), <anonymous>:41:50)
    at Object.<anonymous> (/home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/runtime.js:30:33)
    at Object.search (/home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/compiler/compiler.js:1274:21)
    at Object.Handlebars.VM.invokePartial (/home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/runtime.js:81:28)
    at Object.eval (eval at <anonymous> (/home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/compiler/compiler.js:564:23), <anonymous>:86:17)
    at /home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/runtime.js:30:33
    at /home/tim/workspace/projects/severine/node_modules/assemble/node_modules/assemble-handlebars/node_modules/handlebars/lib/handlebars/compiler/compiler.js:1274:21
    at Object.render (/home/tim/workspace/ae_projects/severine/node_modules/assemble/node_modules/assemble-handlebars/index.js:38:17)
    at Object.render (/home/tim/workspace/projects/severine/node_modules/assemble/lib/engine.js:87:17)

Aborted due to warnings.

如果我注释掉过滤器功能的主体,则组装正常运行。

1 个答案:

答案 0 :(得分:2)

@tim我们通常会在数据上下文和手柄帮助器上的属性名称发生冲突时看到这些错误。

如果您在数据上下文中使用filter作为属性,请尝试使用{{this.filter}}而不是{{filter}}来为Handlebars提供一个提示,即它应该使用属性而不是帮助程序。

这个问题来自this issue on Github。我希望这可以帮助其他人遇到同样的问题。