typescript와 함께 asp.net MVC 5를 사용하고 있습니다. 내 viewmodel 메신저 내 데이터를 내 API에서 내 knockoutObservable 배열 아약스 전화를받을려고. 내 배열 initilize 경우에도 (또는 적어도 내가 있어야한다고 생각). 사람이 얼마나있는 ReservationDay.ts 클래스를 사용하는 나를 설명 할 수Typescript initilize 후에도 undefined이기 때문에 knockoutObservableArray를 푸시 할 수 없습니다.
@section Scripts{
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/knockout")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/calendar")
<script type="text/javascript">
$(function() {
var vm = new ViewModel.Calendar(@Model);
ko.applyBindings(vm);
});
</script>
}
또한 또 다른 질문 : 여기
내 코드입니다 :Errr : TypeError: Cannot read property 'push' of undefined
module Models {
export class ReservationDay {
date: KnockoutObservable<Date>;
place: KnockoutObservable<string>;
avaibleSlots: KnockoutObservable<number>;
instructorId: KnockoutObservable<string>;
constructor(date: Date, place: string, avaibleSlots: number, instructorId: string) {
this.date = ko.observable(date);
this.place = ko.observable(place);
this.avaibleSlots = ko.observable(avaibleSlots);
this.instructorId = ko.observable(instructorId);
}
}
}
module ViewModel {
import ReservationDay = Models.ReservationDay;
export class Calendar {
public days: KnockoutObservableArray<ReservationDay> = ko.observableArray<ReservationDay>();
constructor() {
this.getMonthCalendar(new Date());
}
getMonthCalendar(date: Date) {
var month = date.getMonth() + 1;
$.ajax({
url: 'myApiUrl' + month,
type: 'GET',
dataType: 'json',
async: false,
success(data, textStatus, xhr) {
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
console.log(this.days); // here is undefined
this.days.push(new ReservationDay(data[i].date,data[i].place,data[i].avaibleSlots, data[i].instructorId)); // in this line : error : TypeError: Cannot read property 'push' of undefined
}
console.log("ajax done.");
}
},
error(xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
}
여기 내이다 위와 같이 viewmodel이있는 파일에없는 다른 폴더에 있습니다. My folders img
미리 감사드립니다.
이이 일을 주셔서 감사합니다! 제 두 번째 질문에 대한 대답을 알고 계십니까? 모델을 분리 된 파일로 저장하는 방법? – Bourni