0
나는 작업중인 웹 사이트에 대해 동적 단계 시스템을 만들려고합니다.Typescript & Knockout.js Math.max calculated
현재 단계를 표시하고 현재 및/또는 전체 단계를 조건에 따라 변경해야합니다.
단계 1/2
단계
2/2 불행하게도 나는 내가 나에게 오류를주고 이유를 알 수 없기 때문에 진단하는 방법을 잘 모르겠어요 문제로 실행 해요.
오류 : "catch되지 않은 형식 오류 : 정의되지 않은의 'StepNumberOne'속성을 읽을 수 없습니다"여기
을의 내 코드 :
class ViewModel {
public IsStepOneActive: KnockoutObservable <boolean> ;
public IsStepTwoActive: KnockoutObservable <boolean> ;
public StepNumberOne: KnockoutComputed <number> ;
public StepNumberTwo: KnockoutComputed <number> ;
public Total: KnockoutComputed <number> ;
constructor() {
this.IsStepOneActive = ko.observable(true);
this.IsStepTwoActive = ko.observable(false);
this.StepNumberOne = ko.pureComputed(function() {
if (this.IsStepOneActive()) {
return 1;
} else {
return 0;
}
});
this.StepNumberTwo = ko.pureComputed(function() {
if (this.IsStepTwoActive()) {
return 2;
} else {
return 0;
}
});
this.Total = ko.computed(function() {
return Math.max(this.StepNumberOne(), this.StepNumberTwo);
});
}
}
ko.applyBindings(new ViewModel());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="target">
<div>
<span data-bind="text: StepNumberOne"></span>
<span>/</span>
<span data-bind="text: Total"></span>
</div>
<div>
<span data-bind="text: StepNumberTwo"></span>
<span>/</span>
<span data-bind="text: Total"></span>
</div>
</div>
죄송이 다를 수 있기 때문에이 대리자가 필요
을, 이것은 내가 만든 예입니다, 나는했습니다 데이터 바인딩을 –
@RianMostert 의미 답변을 – jgasiorowski
업데이트했습니다. 대표단이었습니다. 고마워요! –