Skip to content

Instantly share code, notes, and snippets.

@benlesh
Last active August 29, 2015 14:17
Show Gist options
  • Save benlesh/4665c5a4e57036111de1 to your computer and use it in GitHub Desktop.
Save benlesh/4665c5a4e57036111de1 to your computer and use it in GitHub Desktop.
Help me obi-bryn kenobi... you're my only hope
I have a table component that works like this (basically):
{{#nf-table data=someData}}
{{#nf-column}}
{{#nf-header}}Foo{{/nf-header}}
{{#nf-cell}}<button {{action 'fooClicked'}}>{{foo}}</button>{{/nf-cell}}
{{/nf-column}}
{{#nf-column}}
{{#nf-header}}Bar{{/nf-header}}
{{#nf-cell}}{{bar}}{{/nf-cell}}
{{/nf-column}}
{{/nf-table}}
and outputs:
<table>
<thead>
<tr>
<th>Foo</th>
<th>Bar</th>
</tr>
</thead>
<tbody>
<tr>
<td><button action-crap-here>foo value 1</button></td>
<td>bar value 1</td>
<tr>
<tr>
<td><button action-crap-here>foo value 2</button></td>
<td>bar value 2</td>
<tr>
<!-- snip -->
<tr>
<td><button action-crap-here>foo value 100</button></td>
<td>bar value 100</td>
<tr>
</tbody>
</table>
export default Ember.ObjectController.extend({
data: [{ foo: 'foo value 1', bar: 'bar value 1' }, { foo: 'foo value 2', bar: 'bar value 2' }/* ... more ... */]
actions: {
fooClicked: function() {
// THIS DOESN'T GET HIT. :(
console.log('foo was clicked');
}
}
})
<table>
<thead>
<tr>
{{#each col in columns}}
{{view 'nf-table-header' template=col.headerTemplate}}
{{/each}}
</tr>
</thead>
<tbody>
{{#each row in data}}
<tr>
{{#each col in columns}}
{{view 'nf-table-cell' template=col.cellTemplate}}
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment