问题描述
我正在努力适应 Ember.js 和 Handlebars,但有一个问题让我感到困惑.我可能只是遗漏了一些东西,但已经使用了很长时间,并没有发现任何问题.
I'm trying to get used to Ember.js and Handlebars, but one problem is puzzling me. I'm probably just missing something, but has been on it for quite a while and could not find anything wrong.
我有一个简单的模板:
<header>
<h2><a href="#" class="link-box-title">{{project.pid}}-{{projectWindowTitle project}}</a></h2>
</header>
第一个 {{project.pid}} 正确输出 project.pid 值,我想将项目对象传递给下面的辅助函数:
the first {{project.pid}} correctly outputs the project.pid value, and I wanted to pass the project object to the helper function bellow:
Handlebars.registerHelper('projectWindowTitle', function(proj) {
var info = proj.pid;
return info;
});
我过度简化了助手,但结果总是一样的,助手不返回任何东西:
I'm overly simplifying the helper, but the result is always the same, the helper does't return anything:
<a href="#" class="link-box-title"><script id="metamorph-9-start" type="text/x-placeholder"></script>S2S<script id="metamorph-9-end" type="text/x-placeholder"></script>-</a>
我做错了什么?
推荐答案
在 ember.js 中使用把手时,助手签名与普通"把手略有不同.主要区别在于,在调用助手之前,参数并未解析".
when using handlebars in ember.js, the helper signature is a little bit different than with "plain" handlebars. the main difference is that the argument is not "resolved" before the helper is called.
对于您的示例,proj 是project",因此您必须从视图中获取project"的值:
for your example, proj is "project", so you have to get the value of "project" from the view:
Handlebars.registerHelper('projectWindowTitle', function(property, options) {
var project = Ember.getPath(this, property);
var info = project.get("pid");
return info;
});
这篇关于Ember.js 助手无法正确识别参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论