2012-01-10 52 views

回答

2

如果有人需要這個功能,我創建了一個小的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 

還是希望有一個更好的辦法。

+0

你碰巧知道是否有在灰燼的新版本更好的辦法? – Denzo 2013-03-07 05:09:57

7

您可以使用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/