2012-05-11 110 views
1

我想用燼來顯示找到的內容的動態列表。問題是,當我試圖把句柄放在html屬性中時,一切都打破了。Ember把手嵌入ID

RegApp.PatronsFound = Ember.CollectionView.create 
    tagName: 'table' 
    content: [] 
    itemViewClass: Ember.View.extend 
    template: Ember.Handlebars.compile("<td><button onclick='alert({{content.id}})'>{{content.name}}</button>") 
RegApp.PatronsFound.appendTo('body') 

當餵了一塊內容與3的ID和姓名FOO,我希望生成這個網站:

<button onclick="alert(3)">FOO</button> 

相反,我得到這樣的:

<button onclick="alert(&lt;script id=" metamorph-4-start'="" type="text/x-placeholder">3<script id="metamorph-4-end" type="text/x-placeholder"></script>)'&gt;FOO</button> 

回答

2

您可以使用

{{unbound content.id}} 

到arbitrari將值插入您的模板。通常情況下,這些值被包裹在metamorph標籤中,允許顯示的值綁定到後備值,並在後備值發生變化時更新。這隻適用於輸出是常規的HTML,而不是在這種情況下,跨越事件處理程序和嵌入式JS。 {{unbound}}將該值插入該屬性路徑中一次,而不使用變量標籤,並且如果將來該值發生更改,則不更新。