Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <code>action</code> Handlebars helper, see <a href="http://jsfiddle.net/jmDXP/" rel="nofollow noreferrer">http://jsfiddle.net/jmDXP/</a></p> <p><strong>Handlebars:</strong></p> <pre><code>&lt;script type="text/x-handlebars" id="mainview" &gt; {{#each list}} &lt;div {{action "clicked"}} &gt;{{title}} / {{desc}}&lt;/div&gt; {{/each}} &lt;/script&gt; &lt;script type="text/x-handlebars" &gt; &lt;div id="container"&gt;&lt;/div&gt; {{#view App.TabView}} {{view Ember.TextField valueBinding="title"}} {{view Ember.TextField valueBinding="desc"}} &lt;button {{action "addTab" }} &gt;Add&lt;/button&gt; {{/view}} &lt;/script&gt; ​ </code></pre> <p><strong>JavaScript:</strong></p> <pre><code>var get = Ember.get; App = Ember.Application.create({}); App.Tab = Ember.Object.extend({ title: null, desc: null }); App.TabsController = Ember.ArrayController.create({ content: [], resourceType: App.Tab, addTab: function(title, desc) { this.pushObject(App.Tab.create({ title: title, desc: desc })); }, init: function() { this._super(); var i = 0; for (i = 0; i &lt;= 4; i++) { this.addTab("hola" + i, "test " + i); } } }); App.TabView = Ember.View.extend({ addTab: function() { var title = get(this, 'title'); var desc = get(this, 'desc'); App.TabsController.addTab(title, desc); } }); App.initializeView = Ember.View.create({ templateName: 'mainview', listBinding: 'App.TabsController', clicked: function(view, event, context) { console.log('clicked @', get(context, 'title')); } }); App.initializeView.appendTo('#container');​ </code></pre> <p>Note: in the upcoming version the arguments of an <code>action</code> callback changed, see <a href="https://stackoverflow.com/questions/9530912/emberjs-action-event-target-is-undefined">emberjs action event.target is undefined</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload