2014-08-28 54 views
1

我看到的最後一個職位emberjs bind data attributes和搜查谷歌發現emberjs
http://emberjs.com/api/classes/Ember.View.html
http://emberjs.com/guides/components/customizing-a-components-element/
鏈接,但我無法理解如何創建自己的attributebinding。EmberJS attributeBinding

舉一個例子(這只是我的假設,可能我會遠離真實場景)。請糾正我。

HTML文件包含:
{{視圖App.DatePickerView數據dateBinding = 「RR」}}

app.js文件包含:

attributeBindings: ["data-date"], 
rr: function() { 
    alert("Hello"); 
}, 

我完全搞砸知道如何屬性綁定的作品?

感謝大家提前。

+0

什麼是你期待發生在你設置'數據日期'到'rr'?屬性綁定通常用於將值傳遞到視圖中。在這個視圖中,'this.get('data-date')'的值只是一個字符串'「rr」'。看看這裏的控制檯標籤http://emberjs.jsbin.com/fufuvodupine/1/edit。 – Marc 2014-08-29 03:28:42

+0

我認爲你會將綁定數據屬性與綁定標準html屬性混淆。例如,我經常想在用戶無法點擊時向鏈接添加「禁用」類。對於這種情況,您只需在模板中使用''',並在組件(或之前的控制器)中定義布爾函數'isDisabled()'。無論如何,如果你對你想做什麼給予更多的解釋,我們可以給你更好的建議,告訴你如何在Ember中完成它。 – spinlock 2015-02-18 18:26:58

回答

1

你有沒有嘗試重新打開您的視圖類?

Ember documentation

Ember.LinkView.reopen({ 
    attributeBindings: ['data-toggle'] 
}); 

我也建議轉向從添加數據遠屬性HTML元素,如果可能的話,而不是在灰燼數據模型的使用性能。

0

這是一個真實的例子來跟蹤topheight屬性和設置爲內嵌樣式包裝DIV

attributeBindings: ['customStyle:style'], 
customStyle: computed('top', 'height', { 
    get() { 
     let top = this.get('top'); 
     let height = this.get('height'); 
     return `top:${top}px; height:${height}px;`; 
    } 
}) 

希望它可以幫助