我有一个ArrayController用于日期选择器,其属性来自和从.现在当用户从UI中选择一个新的日期范围时,从值更改.
所以一个观察者来往的功能是触发两次日期范围的单一变化.
我想触发功能只有一个每个日期范围的变化.任何建议如何做到这一点与余烬
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')
});
View in JS Fiddle
解决方法
也许你可以从…上引入一个计算属性,然后在这个属性上插入观察者.默认情况下缓存CP,我认为观察者只会被触发一次.
date: function(){
// return the computed date
}.property('from','to')
dateDidChange: function(){
}.observes('date')
编辑感谢您的小提琴,似乎使用setProperties或开始/结束propertyChanges http://jsfiddle.net/Sly7/zf2q3/1/工作