1

次のようなビューがあるとしましょう。

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

およびクラス定義:

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

およびクラスのインスタンス:

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

私のテンプレートは次のとおりです。

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

そして、私はそれを次のようにレンダリングしたい:

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

それ、どうやったら出来るの?

4

1 に答える 1

3

bindAttr hrefとItemsControllerを使用してこれを行う非常に簡単な方法は次のとおりです。http://jsfiddle.net/nLa8Z/1/詳細なドキュメントについては、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"})
     ]});
于 2012-06-20T00:57:12.973 に答える