繁体   English   中英

来自车把的 EmberJs 函数

[英]EmberJs Function from Handlebars

我正在自己学习 Ember js,我有这个示例代码,它工作正常:

<script>
    window.EmberApp = Ember.Application.create();
    var Marcapagina = Ember.Object.extend({
         convertir_en_link: function() {
            return "<a href='" + this.get("url") + "'>"
            + this.get("nombre")
            + "</a>";
    },
     nombre: "Robert App",
     url: "http://www.google.cl"
    });
</script>

在 html 正文中,我通过这种方式打印了链接:

<script type="text/javascript">
$(document).ready(function(){
 $("#here").append(marcapagina.convertir_en_link());
});
</script>
<div id="here"></div>

我的问题是,有没有办法从把手调用该函数,例如:

<body>
<script type="text/x-handlebars" data-template-name="index">
Here is where i want to print the result of the function, but
{{marcapagina.convertir_en_link()}}
Doesn't works!!!
</script>

我想摆脱这段代码:

<script type="text/javascript">
$(document).ready(function(){
 $("#here").append(marcapagina.convertir_en_link());
});
</script>
<div id="here"></div>
</body>
</html>

您的方法是以一种非预期的方式使用 Ember.Objects。 但是您正在寻找的最终结果是 Ember 的一个非常基本且包含的部分。

这是一个显示“Ember Way”的有效jsbin

如果您刚开始使用 ember,我强烈建议您在此处浏览 Todo MVC 教程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM