Skip to content

Instantly share code, notes, and snippets.

@nem035
Last active March 8, 2016 05:55
Show Gist options
  • Save nem035/04d8637f7a01db3fee0a to your computer and use it in GitHub Desktop.
Save nem035/04d8637f7a01db3fee0a to your computer and use it in GitHub Desktop.
Double each - dynamic binding
import Ember from 'ember';
export default Ember.Controller.extend({
rows: [],
headers: [],
header1: 'title',
header2: 'description',
onHeadersChange: Ember.observer('header1', 'header2', function() {
let headers = [
this.get('header1'),
this.get('header2')
];
let rows = [{
title: '',
description: ''
}];
this.setProperties({
headers,
rows
});
}).on('init')
});
Header 1: {{input type="text" value=header1}}
Header 2: {{input type="text" value=header2}}
<hr />
<table>
<thead>
<tr>
{{#each headers as |h|}}
<th>{{h}}</th>
{{/each}}
</tr>
</thead>
<tbody>
{{#each rows as |r|}}
<tr>
{{#each headers as |h|}}
<td>
<input onkeyup={{action (mut (get r h)) value="target.value"}}>
</td>
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
<hr />
<h3>Rows</h3>
{{#each rows as |r|}}
{{#each headers as |h|}}
Row[{{h}}]: {{get r h}}<br/>
{{/each}}
{{/each}}
{
"version": "0.6.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment