当前位置: 动力学知识库 > 问答 > 编程问答 >

ember.js - How to add a custom cell-template to Ember-Table table

问题描述:

In the past I've used a vanilla handlebars template to create a table with links to other templates like so.

<tbody>

{{#each}}

<tr>

<th>

{{#link-to 'entities.entity' actorId}}{{/link-to}}

</th>

{{#each alsoKnownAs}}

<td>

{{this}}

</td>

{{/each}}

</tr>

{{/each}}

</tbody>

Using the Ember-Table framework i've refactored that template to

<div style="height: 800px;width: 100%;">

{{table-component

hasFooter=false

enableContentSelection=true

columns=columns

content=controller}}

</div>

My Controller now looks like

entitiesController = Ember.ArrayController.extend

sortAscending: true

sortProperties: ['displayName']

profile_link: 'entities/profile_link'

columns: Ember.computed ->

AKA = Ember.Table.ColumnDefinition.create

columnWidth: 750

headerCellName: 'Also Known As'

textAlign: 'text-align-left'

getCellContent: (row) -> row['alsoKnownAs'].join(', ')

displayName = Ember.Table.ColumnDefinition.create

columnWidth: 200

headerCellName: 'Entity Name'

textAlign: 'text-align-left'

TableCellViewClass: 'profile_link'

getCellContent: (row) -> row['displayName']

[displayName, AKA]

and my custom template entities/profile_link

<th>{{#link-to 'entities.entity' actorId}}{{/link-to}}</th>

How do I setup my controller so that when I click on a cell in the 'Entity Name' column it links to my custom template?

网友答案:

Instead of TableCellViewClass: 'profile_link'

you can define the template inline:

tableCellViewClass: Ember.Table.TableCell.extend
        template: Em.Handlebars.compile """
          {{#link-to 'entities.entity' view.cellContent}}
            {{view.cellContent}}
          {{/link-to}}
"""
分享给朋友:
您可能感兴趣的文章:
随机阅读: