CreateItem 호출의 첫 번째 매개 변수가 범위의 변수가 아니므로이 코드는 컴파일되지 않습니다.
abstract class Catalog<ItemType, IRaw> {
private CreateItem<ItemType, IRaw>(c: new (raw: IRaw) => ItemType, raw: IRaw): ItemType {
return new c(raw);
}
public ServiceUrl: string;
public Items: KnockoutObservableArray<ItemType> = ko.observableArray<ItemType>();
public LoadState: KnockoutObservable<LoadState> = ko.observable<LoadState>(LoadState.NotStarted);
private loadChunk(): void {
var that = this;
if (that.LoadState() === LoadState.NotStarted)
that.LoadState(LoadState.Loading);
if (that.LoadState() === LoadState.Loading) {
$.get(this.ServiceUrl, that.getChunkParameters()).then((result: Array<IRaw>) => {
if (result.length === 0) {
that.LoadState(LoadState.Complete)
} else {
for (var raw of result){
let foo = this.CreateItem(ItemType, raw);
that.Items.push(foo);
}
}
});
}
}
CreateInstance에 전달할 수 있도록 일반 매개 변수 ItemType의 값에 대한 변수 참조를 얻으려면 어떻게해야합니까?
당신은 할 수 없습니다. 클래스 만 값으로 사용할 수 있습니다. 다른 유형, 특히 일반 매개 변수는 값이 아니며 typescript가 javascript로 컴파일 될 때 보존되지 않습니다. 해당 변수 loadChunk()
는와 유사한 값 인수로 어떤 식 으로든 명시 적으로 제공되어야 CreateItem()
하거나 Catalog
클래스 의 속성으로 액세스 할 수 있어야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다