[emberjs]将 'on("init")' 添加到 observbes 有什么意义?
[emberjs]what's point of adding 'on("init")' to observabes?
我正在学习 ember-cli-101。它在使用观察者时添加 on('init') 。我试图删除它,但没有任何区别。
我试图阅读 api 文档,但仍然没有任何意义,请帮助我...
autoSave: function() {
var article = this.get('article');
if (!article.get('isNew')) {
this.sendAction('save', article);
}
},
stateChanged: function() {
var article = this.get('article');
if (article.get('isDirty') && !article.get('isSaving')) {
Ember.run.once(this, this.autoSave);
}
}.on('init').observes('article.state')
autoSave:.....
stateChanged: function() {
var article = this.get('article');
if (article.get('isDirty') && !article.get('isSaving')) {
Ember.run.once(this, this.autoSave);
}
}.observes('article.state')
它们的作用其实是一样的,有什么区别...
如果 属性 在观察者初始化之前改变,观察者将不会触发。这就是为什么有时 运行 在初始化时也触发观察者函数是好的。
我正在学习 ember-cli-101。它在使用观察者时添加 on('init') 。我试图删除它,但没有任何区别。 我试图阅读 api 文档,但仍然没有任何意义,请帮助我...
autoSave: function() {
var article = this.get('article');
if (!article.get('isNew')) {
this.sendAction('save', article);
}
},
stateChanged: function() {
var article = this.get('article');
if (article.get('isDirty') && !article.get('isSaving')) {
Ember.run.once(this, this.autoSave);
}
}.on('init').observes('article.state')
autoSave:.....
stateChanged: function() {
var article = this.get('article');
if (article.get('isDirty') && !article.get('isSaving')) {
Ember.run.once(this, this.autoSave);
}
}.observes('article.state')
它们的作用其实是一样的,有什么区别...
如果 属性 在观察者初始化之前改变,观察者将不会触发。这就是为什么有时 运行 在初始化时也触发观察者函数是好的。