Ember-Tableテーブルにカスタムセルテンプレートを追加する方法

StackOverflow https://stackoverflow.com//questions/24023049

  •  21-12-2019
  •  | 
  •  

質問

過去には、Vanilla Handlebarsテンプレートを使用して他のテンプレートへのリンクを含むテーブルを作成しました。

<tbody>
        {{#each}}
            <tr>
                <th>
                    {{#link-to 'entities.entity' actorId}}{{/link-to}}
                </th>
                {{#each alsoKnownAs}}
                <td>
                    {{this}}
                </td>
                {{/each}}
            </tr>
        {{/each}}
        </tbody>
.

Ember-Tableフレームワークを使用すると、そのテンプレートを

にリファクタリングしました
<div style="height: 800px;width: 100%;">
{{table-component
  hasFooter=false
  enableContentSelection=true
  columns=columns
  content=controller}}
</div>
.

私のコントローラー今見ている

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]
.

とマイカスタムテンプレートエンティティ/ profile_link

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

コントローラを設定する方法「エンティティ名」列にあるセルをクリックすると、カスタムテンプレートにリンクしますか?

役に立ちましたか?

解決

TableCellViewClass: 'profile_link'

の代わりに

テンプレートインライン:

を定義できます。
tableCellViewClass: Ember.Table.TableCell.extend
        template: Em.Handlebars.compile """
          {{#link-to 'entities.entity' view.cellContent}}
            {{view.cellContent}}
          {{/link-to}}
"""
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top