【发布时间】:2012-11-09 21:50:43
【问题描述】:
我有一个用于日期选择器的 ArrayController,它具有 to 和 from 属性。现在,当用户从 UI 中选择新的日期范围时,to 和 from 值都会发生变化。
因此,to 和 from 上的观察者函数会触发两次,以实现日期范围的一次更改。
我只想在每个日期范围更改时触发一次该功能。任何关于如何使用 ember 的建议
app = Ember.Application.create();
app.Time = Ember.ArrayController.create({
to: null,
from: null,
rootElement: "#time",
debug1: function() {
this.set('to', 1);
this.set('from', 2);
},
debug2: function() {
this.setProperties( {
'to': 3,
'from': 4
});
},
debug3: function() {
this.beginPropertyChanges();
this.set('to', 5);
this.set('from', 6);
this.endPropertyChanges();
},
search: function() {
alert('called');
}.observes('to', 'from')
});
【问题讨论】:
-
只观察 to 或 from 怎么样?由于当用户选择下一个日期时两者正在发生变化,因此仅依赖两个日期中的一个可能不起作用?
-
还有其他方法可以改变 to 和 from 。所以观察者必须同时在两者上
标签: properties ember.js