Ember.js帮助器未正确识别参数 [英] Ember.js helper not properly recognizing a parameter

查看:83
本文介绍了Ember.js帮助器未正确识别参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图习惯使用Ember.js和Handlebars,但一个问题让我感到困惑。我可能只是丢了一些东西,但已经有一段时间了,找不到任何错误。



我有一个简单的模板:

 < header> 

< h2< a href =#class =link-box-title> {{project.pid}} - {{projectWindowTitle project}}< / a> < / H2>

< / header>

第一个{{project.pid}}正确输出project.pid值,我想将项目对象传递给下面的帮助函数:

  Handlebars.registerHelper('projectWindowTitle',function(proj){

var info = proj.pid;
return info;

});

我过分简化了帮手,但结果总是一样的,帮手没有返回任何东西:

 < a href =#class =link-box-title>< script id =metamorph-9-starttype =text / x-placeholder>< / script> S2S< script id =metamorph-9-endtype =text / x-placeholder>< /脚本>  - < / A> 

我做错了什么?

解决方案

当在ember.js中使用句柄时,帮助器签名与普通句柄有点不同。主要区别是在调用助手之前,参数不是解决。



为您的示例, proj 是项目所以你必须从视图中获取项目的值:

  Handlebars.registerHelper('projectWindowTitle',function ,options){
var project = Ember.getPath(this,property);
var info = project.get(pid);
return info;
});


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.

I have the simple template bellow:

<header>

    <h2><a href="#" class="link-box-title">{{project.pid}}-{{projectWindowTitle project}}</a></h2>

</header>

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>

What am I doing wrong?

解决方案

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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆