emberjs - 财产火灾两次

时间:2012-07-17 15:52:33

标签: ember.js

为什么此代码中的“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')

此输出记录两次。

1 个答案:

答案 0 :(得分:2)

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

视图已重新呈现,并且计算属性尚未缓存。 : - (