将值传递给自定义句柄栏helper,ember项目

时间:2014-01-14 10:02:32

标签: ember.js handlebars.js

我正在Ember创建一个测试项目来学习框架工作。但是,我遇到了一个问题,即创建一个在句柄栏模板中使用的自定义助手。基本上我尝试将两个参数传递给帮助器以返回一个字符串。

帮助器按预期返回一个字符串,但是声明模板中的参数似乎没有像我期望的那样起作用。

这是我的帮手:

Handlebars.registerHelper('backgroundImage', function(id, image) {
  result = id + 'some text' + image;
  new Handlebars.SafeString(result);
  return result;
});

在我的模板中,我使用这样的帮助:

{{backgroundImage item.id item.blog_image.basename}}

然而,它只是“输出item.id some text item.blog_image.basename”而不是它们持有的值。如果单独声明,我可以成功输出item.id的值。

如果有人能指出正确的方向我会非常感激,我可能很想念。

非常感谢

1 个答案:

答案 0 :(得分:0)

请尝试使用此代码:

Ember.Handlebars.helper('backgroundImage', function(id, image) {
result = id + 'some text' + image;
new Handlebars.SafeString(result);
return result;
});

你必须使用Embers的Embers扩展才能正常工作