有沒有辦法從ember.js注入的把手模板剝離綁定標籤?我希望能夠提取沒有任何metamorph script
標籤的html。Ember.js地帶綁定標籤
我有這個related question,但也想問這個更一般的問題。
有沒有辦法從ember.js注入的把手模板剝離綁定標籤?我希望能夠提取沒有任何metamorph script
標籤的html。Ember.js地帶綁定標籤
我有這個related question,但也想問這個更一般的問題。
如果有人需要這個功能,我創建了一個小的jQuery插件做到這一點:
# Small extension to create a clone of the element without
# metamorph binding tags and ember metadata
$.fn.extend
safeClone: ->
clone = $(@).clone()
# remove content bindings
clone.find('script[id^=metamorph]').remove()
# remove attr bindings
clone.find('*').each ->
$this = $(@)
$.each $this[0].attributes, (index, attr) ->
return if attr.name.indexOf('data-bindattr') == -1
$this.removeAttr(attr.name)
# remove ember IDs
clone.find('[id^=ember]').removeAttr('id')
clone
還是希望有一個更好的辦法。
您可以使用unbound
把手助手在單個屬性級別執行此操作。
有上#unbound
塊幫手,這將是你想要做什麼漂亮的正在做的工作:https://github.com/emberjs/ember.js/pull/321
另一種方法是,在你的意見,指定一個普通的把手模板。沒有一個輸出會被綁定。
App.UnboundView = Ember.View.extend({
template: Handlebars.compile("output is: {{msg}} here"),
msg: "not bound"
});
這裏有一個的jsfiddle例如:http://jsfiddle.net/ebryn/zQA4H/
這裏有一個更好的辦法
{{unbound propertyName}}
http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_unbound
你碰巧知道是否有在灰燼的新版本更好的辦法? – Denzo 2013-03-07 05:09:57