簡體   English   中英

灰燼/車把:自定義助手渲染

[英]Ember/Handlebars: Custom helper rendering

在我的自定義幫助程序中,如何呈現一個本身使用幫助程序的按鈕(在本例中為“動作”幫助程序)? 我正在嘗試:

Ember.Handlebars.registerBoundHelper('actionButtons', function(context, options) {
    return new Handlebars.SafeString("<button {{action 'remove'}} class='destroy'>Delete</button>");
}

但是我剛得到一個格式不正確的html的無效按鈕。

您將要在此部分使用而不是幫助器。

{{partial 'buttons'}}

或者你可以做

Ember.Handlebars.helper('actionButtons', Ember.View.extend({
  templateName: 'buttons'
}));

{{actionButtons}}

模板會像

<button {{action 'remove'}} class='destroy'>Delete</button>

或者你可以做

Ember.Handlebars.helper('actionButtons', Ember.View.extend({
  template: Ember.Handlebars.compile('<button {{action 'remove'}} class='destroy'>Delete</button>')
}));

{{actionButtons}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM