Ank*_*wal 9 properties ember.js
我有日期选择器与性能的ArrayController 到和从.现在,当用户从UI中的新的日期范围既向和从值的变化.
因此,在函数上,观察员到并从为日期范围的单一变化引发的两倍.
我想触发每个日期范围变化只有一个功能.任何有关如何使用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')
});
Run Code Online (Sandbox Code Playgroud)
sly*_*7_7 11
也许你可以在引入计算性能from和to,然后再插上这个属性的观察者.由于CP默认是缓存的,我认为观察者只会触发一次.
date: function(){
// return the computed date
}.property('from', 'to')
dateDidChange: function(){
}.observes('date')
Run Code Online (Sandbox Code Playgroud)
编辑感谢你的小提琴,似乎使用setProperties,或开始/结束propertyChanges http://jsfiddle.net/Sly7/zf2q3/1/