簡體   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