세 가지 상태가있는 Ember 뷰를 작성하려고합니다. 특히 "제출"에서 "저장 중 ..."에서 "완료 됨"으로 전환되는 제출 버튼 이 목표를 달성하는 데는 여러 가지 방법이 있지만, 진부한 코드를 쓰지 않고도이를 수행하기 위해 Ember 관점에서 "모범 사례"가 무엇인지 궁금합니다. 이건 정말 못생긴여러 상태가있는 핸들 막대 템플릿
UiControls.SubmitButton = Ember.View.extend({
template: function() {
var template = '{{#if view.isNotStarted}}Submit{{/if}}';
template += '{{#if view.isStarted}} <i class="icon-spinner icon-spin"></i>Saving...{{/if}}';
template += '{{#if view.isFinished}} <i class="icon-check-sign"></i>Finished!{{/if}}'
return Ember.Handlebars.compile(template);
}.property(),
isNotStarted: true,
isStarted: null,
isFinished: null,
classNames: ['btn', 'btn-green'],
isDisabled: false,
click: function(){
if (!this.get('disabled')){
this.set('isNotStarted', false);
this.set('isStarted', true);
this.set('isFinished', false);
this.timer();
}
},
/* Simulates a server call */
timer: function(){
(function(self){
setTimeout(function(){
self.set('isStarted', false);
self.set('isFinished', true);
}, 500);
})(this);
}
});
나에게 - 우리는 핸들 '의도적으로 제한 조건 구문을 작동하기 위해 이벤트를 기반으로 개별 부울 값을 설정하는 :
현재 나는 다음과 같은 코드가 있습니다.
내가 무엇 을 원한다면은 Ember StateManager 속성 (Handlebars 구문으로는 불가능)과 같은 것을 받아들이는 핸들 바 구조입니다. 또는 최소한 StateManager에서 계산 된 속성을 기반으로 템플릿을 변경하고 싶습니다 (다시는 불가능). 그래서 제 질문은 위의 코드를 작성하여 상태 복제를 많은 불리언 플래그 조작을 통해 수동으로 처리하는 코드 중복을 방지하는 더 좋은 방법이 있습니까?