【发布时间】:2013-03-13 05:07:01
【问题描述】:
我有一个带有 lambda 的小胡子模板,如下所示:
{{#myfunc}}myvalue{{/myfunc}}
被 hogan.js 预编译成这样:
define(['hogan'],
function (Hogan) {
var template = new Hogan.Template(function (c, p, i) {
var _ = this;
_.b(i = i || "");
if (_.s(_.f("myfunc", c, p, 1), c, p, 0, 11, 18, "{{ }}")) {
_.rs(c, p, function (c, p, _) {
_.b("myvalue");
});
c.pop();
}
return _.fl();;
});
return function (context, partial, indent) {
return template.render(context, partial, indent);
};
});
我使用 Marionette.ItemView 渲染模板,将 lambda 函数传递给 Backbone.Model,如下所示:
myfunc: function (key) { console.log("key", key); }
奇怪的事情:函数 myfunc 将被调用并记录到控制台,但模板没有传递密钥。 我读到了 Hogan 在预编译模式下不支持 Lambda(大约一年前 - 我想这是固定的) - 但如果是这样,它是怎么发生的,那 myfunc 被调用了吗?
我在我的 vendor/hogan.js 库中进行了一些调试 - 看起来 hogan 无法看到 lambda-tags 之间的值(这里:myvalue)。
有人见过这个吗?
【问题讨论】:
-
您找到解决方案了吗?我也有类似的问题
-
不,只是避免了预编译。 github上有一个补丁,但我没有设法让它运行。
标签: javascript lambda mustache precompiled hogan.js