如何在键上调用 javascript 中的函数
How to call a function in javascript on a key
`import Ember from 'ember'`
DatePickerComponent = Ember.Component.extend
dateFormat: 'dd.mm.yy'
today: currentDate
currentDate: ->
today = Date()
today
export default DatePickerComponent
引用错误,当前日期未定义。也得到它的时候
today: currentDate
我该如何称呼它?
我想访问今天的车把文件。
我建议回过头来研究 Ember 对象模型和计算属性。模板可以显示的是属性。你要
currentDate: function() {
return Date();
}.property()
或其等效的 CS。
然后在你的模板中
Today is {{currentDate}}.
当你说
today: currentDate
您正在将 today
属性 的值设置为名为 currentDate
的局部变量,而不是名为 currentDate
的对象 属性。没有名为 currentDate
的局部变量。因此 ReferenceError
。如果你想设置一个 属性 等于另一个 属性 的值(尽管这里似乎没有必要),你可以这样做:
today: function() {
return this.get('currentDate');
}.property('currentDate')
或更简单地说
today: Ember.computed.alias('currentDate')
`import Ember from 'ember'`
DatePickerComponent = Ember.Component.extend
dateFormat: 'dd.mm.yy'
today: currentDate
currentDate: ->
today = Date()
today
export default DatePickerComponent
引用错误,当前日期未定义。也得到它的时候
today: currentDate
我该如何称呼它?
我想访问今天的车把文件。
我建议回过头来研究 Ember 对象模型和计算属性。模板可以显示的是属性。你要
currentDate: function() {
return Date();
}.property()
或其等效的 CS。
然后在你的模板中
Today is {{currentDate}}.
当你说
today: currentDate
您正在将 today
属性 的值设置为名为 currentDate
的局部变量,而不是名为 currentDate
的对象 属性。没有名为 currentDate
的局部变量。因此 ReferenceError
。如果你想设置一个 属性 等于另一个 属性 的值(尽管这里似乎没有必要),你可以这样做:
today: function() {
return this.get('currentDate');
}.property('currentDate')
或更简单地说
today: Ember.computed.alias('currentDate')