루트 참조를 window.Xrm 객체에서 얻는 것 자체는 피할 수 없을 것 같지만, 그 접근을 감싸 두면 한 번만 하면 됩니다.
알맞은 ts 템플릿을 설치했다면, 즉:
Install-Package xrm.TypeScript.DefinitelyTyped
이 정도로 간단하게 될 겁니다
class CrmAccess {
constructor(private context: Xrm.XrmStatic) { }
read() {
//stay within the typed environment
//return this.context.Page....;
}
}
그다음 아래처럼 한 번만 초기화하세요
var crmAccess = new CrmAccess(window.Xrm);
crmAccess.read();
영어에서 번역·원문 보기I don't think you can avoid obtaining the root through the window.Xrm object, but wrapping that access means doing it only once.
With the appropriate ts templates installed - namely:
Install-Package xrm.TypeScript.DefinitelyTyped
Something this straightforward should work
class CrmAccess {
constructor(private context: Xrm.XrmStatic) { }
read() {
//stay within the typed environment
//return this.context.Page....;
}
}
Then initalise it just once as follows
var crmAccess = new CrmAccess(window.Xrm);
crmAccess.read();