1
我有我注入我的應用程序控制器,像這樣(從ember js cookbook拍攝)自定義ClockService對象:燼控制器:計算財產不重新計算折扣注入屬性
App.ClockService = Em.Object.extend({
pulse: Ember.computed.oneWay('_seconds').readOnly(),
tick: function() {
var clock = this;
Ember.run.later(function() {
var seconds = clock.get('_seconds');
if (typeof seconds === 'number') {
clock.set('_seconds', seconds + (1/4));
}
}, 250);
}.observes('_seconds').on('init'),
_seconds: 0
});
Ember.Application.initializer({
name: 'clockServiceInitializer',
initialize: function(container, application) {
container.register('clock:service', App.ClockService);
application.inject('controller:application', 'clock', 'clock:service');
}
});
而且我創建的應用程序中的計算性能從脈衝屬性控制器在時鐘服務:
App.ApplicationController = Em.ObjectController.extend({
currentTime: function(){
return moment().format('MMMM Do YYYY, h:mm:ss a');
}.property('clock.pulse')
});
時間戳(使用Momentjs)是在屏幕上的主應用程序可見,但它不與脈衝重繪。難道我做錯了什麼?
UPDATE:
以下應用牽引銷更新,我現在有如下工作方案:
App.ApplicationController = Em.Controller.extend({
setTime: function() {
var time = moment().format('MMMM Do YYYY, h:mm:ss a');
this.set('currentTime', time);
Em.run.later(this, this.setTime, .9999);
}.on('init'),
currentTime: undefined
});
感謝您的提示,併爲頭頂+1(無雙關語意)。 – coderatchet
雖然我有一個問題,我希望應用程序路由來管理模型,並簡單地使用Em.Controller禁止我這樣做,我將如何避免出現'錯誤:斷言失敗:錯誤:斷言失敗:無法委託set'(currentTime',2014年4月28日,下午5:37:52)到對象代理的'content'屬性:其'content'未定義.'我的applicationRoute已經返回一個模型 –
coderatchet
out'currentTime:undefined'是問題所在。你有沒有在jsbin中定義它的原因? – coderatchet