2

为什么这段代码中的“fullName”函数会执行两次?

Person = Ember.Object.extend({
  // these will be supplied by `create`
  firstName: null,
  lastName: null,
  fullName: function() {
    console.log('Full name function...');
    var firstName = this.get('firstName');
    var lastName = this.get('lastName');
    return firstName + ' ' + lastName;
  }.property('firstName', 'lastName')
});

App.tom = Person.create({
  firstName: "Tom",
  lastName: "Dale"
});

App.UsersView = Ember.View.create({
    templateName: 'users',
    users: [App.tom]
});

稍后在 google-chrome 控制台中:

App.tom.set('firstName', 'John')

这输出记录两次。

4

1 回答 1

2

确实像一个错误(添加了一个 JSFiddle 来说明:http: //jsfiddle.net/MikeAski/GRvgt/)...

视图被重新渲染,计算的属性还没有被缓存。:-(

于 2012-07-17T16:20:52.093 回答