How do I make the html attribute's value dependent on the item being rendered by an Ember.js view?

Let's say I have a view like so:

App.AnchorView = Ember.View.extend({
  tagName: 'a',
  attributeBindings: ['href']
});

and a class definition:

App.Item = Ember.Object.extend({
  name: "Unknown Entry",
  location: ""
});

and an instance of the class:

App.Item.create({
   name: "Google",
   location: "http://www.google.com" 
});

and my template is:

{{#view App.AnchorView}}{{name}}{{/view}}

and I want it to render as:

<a href="http://www.google.com">Google</a>

How do I do that?

Answers


Here's a super quick way to do it using bindAttr href and an ItemsController: http://jsfiddle.net/nLa8Z/1/ For more detailed documentation check out http://emberjs.com/documentation/#toc_binding-element-attributes-with-bindattr

{{#each App.ItemsController}}
     <a {{bindAttr href="location"}}>{{name}}</a>
{{/each}}

App.ItemsController = Ember.ArrayController.create({
     content: [
         App.Item.create({ name: "Google", location: "http://www.google.com"})
     ]});

Need Your Help

File Scope and Global Scope: C & C++

c++ c scope global-scope

I am a student and I am confused about global and file scope variables in C and C++.