Ember.js 助手无法正确识别参数

编程入门 行业动态 更新时间:2024-10-28 16:18:08
本文介绍了Ember.js 助手无法正确识别参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力适应 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:关键词]

本文发布于:2023-03-31 10:35:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/801411.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:助手   正确   参数   Ember   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!