Думаю, получение корневой ссылки через объект 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();