【问题标题】:How to create an external link from emberjs loop?如何从 emberjs 循环创建外部链接?
【发布时间】:2013-08-27 12:22:01
【问题描述】:

我正在遍历模型中的多个项目。对于每个项目,我想为我的应用程序中未使用 emberjs 的页面创建一个外部链接。我认为这将是微不足道的,但它并没有像我想象的那样工作。

这就是我所拥有的:

<tbody>
   {{each model itemViewClass=App.ColorView}}
</tbody>

<script type="text/x-handlebars" id="colorTemplate">
   <tr>
                <td>{{date}}</td>
                <td><a href="/myapp/colors/{{id}}/shades">{{name}}</a></td>
    </tr>
</script>

App.ColorView = Em.View.extend({
    templateName: 'colorTemplate'
});

我认为这会创建如下链接:

/myapp/colors/5/shades
/myapp/colors/45/shades
/myapp/colors/6/shades
...etc.

但是,链接是这样创建的:

localhost:8080/myapp/colors/%3Cscript%20id='metamorph-33-start'%20type='text/x-placeholder'%3E%3C/script%3E56%3Cscript%20id='metamorph-33 -end'%20type='text/x-placeholder'%3E%3C/script%3E/shades

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    你应该为 {{#each}} 集合视图实现一个 itemController。在该 itemController 中,您可以使用计算属性将 url 生成为

    url : function () {
     return "/myapp/colors/"+this.get('id')+"/shades";
    }.property()
    

    这是Sample Bin

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      您应该为此使用{{bindAttr href="url"}}url是生成url的方法

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-09
        • 1970-01-01
        • 1970-01-01
        • 2021-10-03
        • 2016-11-28
        • 2021-09-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多