简体   繁体   English

如何将object中的emberjs变量值附加到我的锚标记href?

[英]How can I append the value of emberjs variable in object to my anchor tag href?

I want something like below 我想要下面的东西

<a href="/Admin/MenuEdit/{{ResAdmin.adminController.selectionMenu}}">Edit Selected Menu</a>

selectionMenu is a variable in ResAdmin.adminController Ember Object. selectionMenu是ResAdmin.adminController Ember Object中的变量。

In order to declare a binding for an attribute, you'll need to use bindAttr . 为了声明属性的绑定,您需要使用bindAttr You can use this helper to bind an attribute either to a global path or to a variable in the current context, such as your view. 您可以使用此帮助程序将属性绑定到全局路径或当前上下文中的变量(例如视图)。

For instance, you might have a template like this: 例如,您可能有这样的模板:

<a {{bindAttr href="menuUrl"}}>Edit Selected Menu</a>

Which is bound to a property in your view, like this: 哪个绑定到视图中的属性,如下所示:

App.MyView = Ember.View.extend({
    menuUrl: function() {
        return "/Admin/MenuEdit/" + this.get("App.adminController.selectionMenu");
    }.property("App.adminController.selectionMenu)            
});

I created a fiddle for this example. 我为这个例子创造了一个小提琴

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

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