[英][Ember.js]Pass template helpers created by template helpers as a attribute to a component in order to use it in the components template?
我正在使用paper-data-table ,它是ember-paper的擴展。 兩者都使用了我之前沒有看到的技術,我將其描述為“模板助手創建模板助手”。
這是灰紙工具欄組件的一個簡單示例
{{#paper-toolbar as |toolbar|}}
{{#toolbar.tools}}
{{#paper-button}}
Go Back
{{/paper-button}}
<h2>Toolbar with Standard Buttons</h2>
<span class="flex"></span>
{{#paper-button raised=true}}
Learn More
{{/paper-button}}
{{#paper-button mini=true aria-label="Favorite"}}
{{paper-icon "favorite"}}
{{/paper-button}}
{{/toolbar.tools}}
{{/paper-toolbar}}
有一個新的模板助手創建了{{#paper-toolbar as |toolbar|}}
。 在我的用例中,我想將由紙數據表模板助手(/ component?)創建的行模板助手傳遞給另一個組件,以封裝其中的邏輯。
我試圖將其作為參數傳遞:
{{#paper-data-table
sortProp='sort'
sortDir='asc'
as |table|
}}
{{#table.body as |body|}}
{{#each questions as |question index|}}
{{question-row
row=body.row
}}
{{/each}}
{{/table.body}}
{{/paper-data-table}}
但是,當嘗試在question-row
組件的模板中使用helper(/ component)時
{{#row as |row|}}{{/row}}
我收到以下錯誤:
Assertion Failed: A component or helper named "row" could not be found Error
所以我想問問那是否可行以及如何運作。
此方法稱為上下文組件,我能夠通過問題行組件中的以下代碼來解決該問題:
{{#component row as |row|}}
{{#row.cell}}
HALLO
{{/row.cell}}
{{/component}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.