【发布时间】:2016-06-27 11:07:52
【问题描述】:
我有一个演示控制器:
import Ember from 'ember';
export default Ember.Controller.extend({
firstName: 'Bob',
lastName: 'Smith',
emailAddress: 'bobsmith@gmail.com',
fullName: Ember.computed('firstName', 'lastName', function() {
console.log('executed!');
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
actualEmailAddress: Ember.computed('emailAddress', function() {
console.log('actualEmailAddress function is called: ', this.get('emailAddress'));
})
});
当我在浏览器的本地主机上运行应用程序时,我打开 ember 检查器并运行:
$E.get('actualEmailAddress')
这会返回:
actualEmailAddress function is called: bobsmith@gmail.com
但是当我第二次运行它时,我会得到undefined
当我运行$E.get('fullName')时也是如此
返回
executed!
"Bob Smith"
但是当我再次运行它时,它只返回Bob Smith,而不是console.log
为什么会这样?
谢谢!
【问题讨论】:
标签: ember.js computed-properties